Bug Tracker

Modify

Ticket #7241 (closed bug: duplicate)

Opened 3 years ago

Last modified 3 years ago

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

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

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.

Change History

comment:1 Changed 3 years ago by addyosmani

  • Keywords string support data added
  • Priority changed from undecided to low
  • Status changed from new to closed
  • Component changed from unfiled to data
  • Resolution set to duplicate

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.

comment:2 Changed 3 years ago by addyosmani

Duplicate of #7231.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.