2

So I've been banging my head against the keyboard here for a while, and finally managed to boil this strange behavior down to its core.

It seems that in Chrome, when you make a JSONP request using JQuery.ajax() and the server returns a 404, none of the callbacks get called. Callbacks supplied to neither fail(), always() or done() are called.

In IE10 the callbacks are called as expected.

Simple example (which you can also check out in this fiddle:

$.ajax("https://www.google.com/notexists",
{
    dataType: "jsonp",
}
).always(function ()
{
    alert("Call ended."); // This never gets called in Chrome!
});

I'm using jQuery 1.9.1.

Is anybody else seeing this behavior? Is there any other explanation for it than this being a bug in jQuery?

Decorum
  • 31
  • 2
  • 2
    Sadly jsonp requests do not trigger fail callbacks, and as a result, they also don't trigger the always callback on a fail. This is not a bug, it's the intended behavior, i'm guessing due to lack of a cross-browser solution. – Kevin B May 01 '13 at 18:05
  • This is just how JSONP works. http://forum.jquery.com/topic/jquery-ajax-with-datatype-jsonp-will-not-use-error-callback-if-request-fails – gen_Eric May 01 '13 at 18:06
  • JSONP is not really AJAX. It uses a browser trick that precludes detecting errors. – Barmar May 01 '13 at 18:16
  • Thanks for the comments. Understood. But isn't it fair to say that the fact that this behaves differently in IE10 vs Chrome should be considered a bug? After all, isn't jQuery supposed to provide consistent cross-browser behavior? If this is just how JSONP works, then shouldn't the callbacks be suppressed in ALL browsers? – Decorum May 01 '13 at 18:33
  • This is an old question, but anyone who read this try using `timeout`. http://stackoverflow.com/questions/2493974/how-to-callback-a-function-on-404-in-json-ajax-request-with-jquery#answer-2537559 – Sanghyun Lee Aug 11 '14 at 08:27

0 Answers0