jQuery and IE headache

After much work on the new phpSysInfo interface, I decided to test it in IE.

Since 99% of the code is pure jQuery code (we are talking about 400 lines of JavaScript) I had no reason to believe that it would fail. But off course, it did.

When I loaded the page, it called the ajax error callback which should be called if the ajax request fails (ie 404). I scratched my head and thought it must be a jQuery bug (which it later appeared to be) but I could not believe that ajax was broken in jQuery. So i commented out all my code in my success callback. And it worked. After much commenting I ended up with one line that make the script fail:
version = $("Generation", xml).attr("version");

At this point I got really confused, so I logged on #jquery@irc.freenode.net and asked there.

To my luck John Resig got interested and wanted to help out.
He quickly isolated one bug in jQuery that had confused both of us for a while :
An error in success() triggers the error() callback .

But things where still failing in IE.
Just out of luck i did a
alert(version);
while
version = $("Generation", xml).attr("version");
was commented out. It popped up 'object'. I got really confused, but I was probably the only one.

<JohnResig> xqus: oh yeah, IE introduces a global variable for each element on the page with the same ID
<JohnResig> xqus: but if you overwrite it, it should really matter, I would assume
<xqus> JohnResig, hm.. let my try to see if that is the problem with that other functions.
<xqus> JohnResig: I actually think that's it.
<JohnResig> xqus: I forgot to check, do you ever do: "var version" anywhere, to define it?
<xqus> JohnResig: I'm a PHP guy, you guess.
<JohnResig> :)
<xqus> JohnResig: That did the trick :p
<JohnResig> well that's a kick in the nuts

So, In short:
I had a div with id="version", that made the JavaScript fail unless I did
var version;
version = $("Generation", xml).attr("version");

Cool eh?

There was created a bug issue for that problem too, although it proved to be more of a stupid developer error.
Exception in IE when accessing XML attribute.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><pre><blockquote>
  • Lines and paragraphs break automatically.
  • Insert Flickr images: [flickr-photo:id=230452326,size=s] or [flickr-photoset:id=72157594262419167,size=m].

More information about formatting options