Skip to main content

Bug Tracker

Side navigation

#7241 closed bug (duplicate)

Opened October 18, 2010 02:53PM UTC

Closed October 18, 2010 02:59PM UTC

Last modified October 18, 2010 02:59PM UTC

.data() doesn't parse JSON strings, but accepts all other JSON notation

Reported by: leo@snorland.com Owned by:
Priority: low Milestone: 1.5
Component: data Version: 1.4.3
Keywords: string support data Cc:
Blocked by: Blocking:
Description

Regarding the broken .data() functionality in jQuery 1.4.3

It is expected that .data() can be used to pass a JSON encoded variable into a data attribute and having it fetched in the same structure with .data() by the client. This is true for null, boolean, number, array and object but not strings!

What I expect: To retain the structure, variables & types of the data.

What actually happens: Strings are either unparsed or accidentally parsed as something else. There is no functionality for accurately retaining the contents of strings.

More info on the problem here: http://www.reddit.com/r/programming/comments/ds42b/jquery_143_released/c12l6z9

And a visual of how the data parsing should work...

When I use:

$("div").data("variable");

The result from .data() should simply be equivalent to this:

try{
   var variable = jQuery.parseJSON( $("div").attr("data-variable") );
}catch(e){
   var variable = $("div").attr("data-variable");
}

But instead it is not simply parsing JSON first, it is parsing everything except strings, and leaving anything else as raw, unparsed strings.

Attachments (0)
Change History (2)

Changed October 18, 2010 02:59PM UTC by addyosmani comment:1

component: unfileddata
keywords: → string support data
priority: undecidedlow
resolution: → duplicate
status: newclosed

The bug submitted sounds a lot like #7231. I'll reference your ticket in the other thread but will be closing this as a duplicate as both refer to the broken string support.

Changed October 18, 2010 02:59PM UTC by addyosmani comment:2

Duplicate of #7231.