I am requesting a URL with ajax that results in a HTTP header code 500. I would expect this to trigger the error function:
$.ajax({
url: "http://xxx",
dataType: "jsonp",
crossDomain: true,
success: function( data ) {
alert('success');
},
error: function () {
alert('error');
}
});
This works in safari, but fails in chrome and firefox.
What am I doing wrong?
This is the latest jquery 1.4.X, for reasons I cannot upgrade to later versions..
The response sends a HTTP code 500, content type application/json and contents:
jsonp1310063232212({"error":{"reason":"User not found"}})
As stated on JQuery documentation [1] the error handler is not called for cross-domain script and JSONP requests. It worked (not always) on older versions of JQuery.
I solve using a compact and effective plugin that include a nice error handler: http://code.google.com/p/jquery-jsonp/
Download it and add it to head:
Then you can use function $.jsonp() similar to $.ajax():
[1] http://api.jquery.com/jQuery.ajax/
There seems to be outstanding issues with this see. Abort JSONP ajax request with jQuery
It looks like
crossDomain:
wasn't added until jQuery 1.5.http://api.jquery.com/jQuery.ajax/
Like Martin Larente suggested in his comment, it could be an issue with how different browsers or jQuery detects/reports JSONP errors.