Skip to main content

Bug Tracker

Side navigation

#2568 closed bug (fixed)

Opened March 20, 2008 02:52PM UTC

Closed February 05, 2009 06:30PM UTC

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();

}

Attachments (0)
Change History (7)

Changed May 16, 2008 03:28AM UTC by flesler comment:1

need: CommitTest Case

Test case please ?

Changed February 03, 2009 03:30AM UTC by dmethvin comment:2

resolution: → invalid
status: newclosed

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

Changed February 04, 2009 10:22AM UTC by Jacob W comment:3

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.

Changed February 05, 2009 12:44AM UTC by dmethvin comment:4

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

Changed February 05, 2009 09:51AM UTC by Jacob W comment:5

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!

Changed February 05, 2009 10:31AM UTC by Jacob W comment:6

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...

Changed February 05, 2009 06:30PM UTC by dmethvin comment:7

resolution: → fixed
status: reopenedclosed

OK, I'll close it then.