When jQuery returns “failed” in IE – and how it’s probably resolved21st of Mar 2010 - Samuli Hakoniemi

When jQuery returns failed in IE - and how it's probably resolved
In web development, I love facing unexpected problems I haven’t seen before. It’s an excellent situation to learn new things. And the moment right after I’ve found a solution – it’s a perfect moment. But when I can’t find a solution, no matter how hard I try, and especially when I can’t find anything from Google that could help me.. well, I get very frustrated. In this brief article, I’ll go through one problematic situation that really got me frustrated. Plus, this hopefully can be found via Google and therefore works as a solution to anyone who’s facing a same problem.
Last week at work, I encountered a very peculiar problem in Internet Explorer. There were several IE-related bugs reported in a certain part of the service. However, I couldn’t reproduce them and I expected these bugs had been fixed during other updates in the code.. ..until it suddenly happened. All the tested versions of IE’s (6, 7, 8) started reporting either error “failed” or “unexpected error”, pointing to jQuery’s code. And there worst part was that error occurred occasionally, although nothing was changed. In this case, there’s jQuery 1.3.2 in use. Error message didn’t help and the line it was pointing to, belonged to a internal / helper function into jQuery. At first, errors disappeared after some fixes I expected to resolve the situation. But, like I mentioned earlier: these errors were occasional. I didn’t have anything that could have helped me at least a little on tracking this problem (later I found not even unit tests would’ve solved this – although it’s not an argument why I didn’t have unit testing for javascript). So, my only choice was trying to isolate the problem function by function, line by line. Ultimately I found that all the errors were caused by event handler bindings made with function $.fn.live(). I couldn’t blame the selectors being too unprecise, although I reduced the amount of troublemakers by fine-tuning them. In addition, I found that wrapping them in setTimeout() with small delay would have possibly fixed the problem. Also, IE6 had the most problems, while IE7 started to feel stable. Most likely there was something going on with perfomance. However, after all this I wasn’t in a mood to expect these problems were completely solved. So I ended up binding event handlers with $.fn.bind() whenever something was dynamically added. It meant more lines of code, but it also meant that no errors were occurred ever again. The point of this article can be put in one sentence: if you receive an error with message “failed” or “unexpected error” from jQuery and this happens only in Internet Explorer, comment out every possible live() binding and try again.

10 thoughts on “When jQuery returns “failed” in IE – and how it’s probably resolved

  1. Niall on said:

    Encountered this and reworking of .live() calls worked a treat. Many thanks!

  2. Encountered the same problem and used livequery that did teh trick by just replacing live functions call by livequery.
    http://plugins.jquery.com/project/livequery

    Thank you so much for sharing, your post gave me the right direction.

  3. Jonatan on said:

    Friends, I am having the same problem, but did not understand the solution.

    Can you help?

  4. Pingback: Potential solution for the IE8 javascript "Failed" error message | Matt Bee Blog

  5. Paul C on said:

    Thanks alot for this, very odd error, solved by moving a .live from the main page into the bottom of the ajax payload and changing it to .bind. IE really doesn’t make life easy :/

  6. tom on said:

    Thanks dude. Your help is really appreceated. I got stuck for days with this odd IE behaviour in a very complex ajax webste using gogle maps api as well.

    the livequery plugin solved the problem for me..

    IE sux so bad ;-(

  7. exdents on said:

    use jquery plot , Failed

    Can you help ?

  8. wyysf on said:

    After I use PIE.htc ,swfupload plugins can’t work and IE browser(678)throw an error “SCRIPT16389: Failed ” and the error in jQuery.
    can you help me?

  9. dennis on said:

    Thanks for the suggestions! jQuery has done away with the “.live()” functionality with the “.on()” functionality.

    Also, wyysf, in the PIE.htc file, look for “url(about:blank)” and replace this with “none”

  10. bashi on said:

    Setting setTimeout() solved my problem! Thanks!