Bug Tracker

Opened 4 years ago

Closed 4 years ago

Last modified 3 years ago

#14101 closed bug (fixed)

Version 1.10 .data() differs from 1.8 when getting data from non-existent object

Reported by: Alex Robbin <agrobbin@…> Owned by: gnarf
Priority: high Milestone: 1.11/2.1
Component: data Version: 1.10.1
Keywords: Cc: gnarf
Blocked by: Blocking:


This is a re-posting of ticket #13785, as it is still a problem in jQuery 1.10 but I am not able to re-open that ticket. I have reposted the information with new jsFiddles below.

In jQuery 1.8.3 (jsFiddle here), when you have attempted to retrieve a data key from an element that doesn't actually exist on the page, the result from data() was "undefined". In jQuery 1.9.1 (jsFiddle here) and jQuery 1.10.1 (jsFiddle here), that result is now "null". I have just had the jsFiddles do an alert showing what the value is when attempting to call .data() on an element that doesn't exist.

When gathering some data values from an element in order to pass them along to a subsequent POST request, I am building a basic javascript object that I then pass to $.post(). In jQuery 1.8.3, if the element did not exist (which can definitely happen on occasion), the params looked like this:

{id: undefined, type: undefined}

When $.post() then took that object to parameterize it, no parameters are actually POSTed to the /test/endpoint. However, in jQuery 1.9.1, the params look like this:

{id: null, type: null}

Because null values aren't stripped out/ignored when doing a $.post() like undefined values are, two empty values are POSTed, which our back-end system is not expecting.

Interestingly, when you call .data() on an element that does exist but has no value for the supplied data key, the return value is undefined in jQuery 1.9.1. It is only when the element doesn't actually exist on the page that the value has changed between 1.8.3 and 1.9.1.

Again, I am not sure if this is done purposefully or not, but in the gist that I have linked to, you'll see that the implementation does actually change (and jQuery migrate does not mitigate it).

I hope I have been clear in explaining the change, and any insight you guys can give me would be greatly appreciated. Thanks!

Change History (9)

comment:1 Changed 4 years ago by timmywil

Component: unfileddata
Milestone: None1.10.3/2.0.4
Priority: undecidedhigh
Status: newopen

comment:2 Changed 4 years ago by Rick Waldron

Owner: set to Rick Waldron
Status: openassigned

comment:3 Changed 4 years ago by Rick Waldron

Cc: gnarf added
Owner: Rick Waldron deleted
Status: assignedopen

Actually, I'm going to bail out for this one and ping Corey

comment:4 Changed 4 years ago by dmethvin

Milestone: 1.10.3/

Bulk update for new milestone

comment:5 Changed 4 years ago by Rick Waldron

Owner: set to gnarf
Status: openassigned

comment:7 Changed 4 years ago by Rick Waldron

Resolution: fixed
Status: assignedclosed

comment:9 Changed 3 years ago by dmethvin

Summary: JQUERY 1.10'S .DATA() RESULT DIFFERS FROM 1.8 WHEN ATTEMPTING TO GET DATA FROM A NON-EXISTENT OBJECT.Version 1.10 .data() differs from 1.8 when getting data from non-existent object
Note: See TracTickets for help on using tickets.