Bug Tracker

Opened 12 years ago

Closed 11 years ago

#2568 closed bug (fixed)

elem has no properties error in nodeName method

Reported by: hobbit Owned by:
Priority: major Milestone: 1.2.4
Component: core Version: 1.2.3
Keywords: Cc:
Blocked by: Blocking:

Description

When we run the $.getJSON method sometimes an unusual issue rise in. "elem has no properties in 660 line."

nodeName: function( elem, name ) {

return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();

}

vs

nodeName: function( elem, name ) {

return elem && elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();

}

Change History (7)

comment:1 Changed 12 years ago by flesler

need: CommitTest Case

Test case please ?

comment:2 Changed 11 years ago by dmethvin

Resolution: invalid
Status: newclosed

Since this was reported against 1.2.3 and never got a test case, I'm closing it.

comment:3 Changed 11 years ago by Jacob W

Resolution: invalid
Status: closedreopened

I just encountered this error as well - it manifests any time I try to load a JSON object containing an empty array, eg

{ "response": {

"name":"testcase", "properties": [ ]

} }

Unless I've misunderstood, this is a valid object; it's certainly understood by javascript when not using jQuery and JSON Lint likes it. I'm guessing that the error appears when trying to run nodeName on the first member of the array, which obviously doesn't exist.

My fix is:

try {

return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();

} catch (e if e instanceof TypeError) {

return false;

}

I'm assuming that this will be better than checking that elem.nodeName is defined, since this error doesn't seem common. I'm not an expert on the inner working of jQuery, however, so this might be better fixed where the function is called.

Jacob.

comment:4 Changed 11 years ago by dmethvin

Hey, I should close stale tickets more often. Jacob, do you have a snippet of the ajax call you make?

comment:5 Changed 11 years ago by Jacob W

It's just $.getJSON(path,function(response). The error occurs immediately, and code in the function isn't executed. It's loading a document that looks like this:

{ "response":{ "totalresults":"2588", "first":"0", "length":"15", "items":[ {

"titre": "TITLE", "sid":"2",

"instruments": "", "duree": "6:33",

"lmoc":"1", "fav":"0", "weight":"2587"

},{

"titre": "TITLE, "sid":"3",

"instruments": "", "duree": "7:02",

"lmoc":"1", "fav":"0", "weight":"2586"

}]

} }

Any time items is empty - i.e. "items":[] - I get this error.

In fact the "fix" I suggested above doesn't work - IE and Firefox are both fine with it, but in Safari it results in a "jQuery not found" error when the page loads!

comment:6 Changed 11 years ago by Jacob W

Slightly embarrassingly I was on an old version of jQuery - 1.2.6. This seems to be fixed in 1.3.1. Turns out I hadn't updated quite as much as I thought.

Sorry for reopening the bug...

comment:7 Changed 11 years ago by dmethvin

Resolution: fixed
Status: reopenedclosed

OK, I'll close it then.

Note: See TracTickets for help on using tickets.