Skip to main content

Bug Tracker

Side navigation

#11680 closed bug (patchwelcome)

Opened May 01, 2012 08:34PM UTC

Closed May 11, 2012 05:31PM UTC

Last modified February 21, 2013 01:50PM UTC

Cross-Domain ajax request error handler does not get called

Reported by: geoffreyk Owned by:
Priority: low Milestone: None
Component: ajax Version: 1.7.2
Keywords: Cc: jaubourg
Blocked by: Blocking:
Description

Revisiting, and expanding http://bugs.jquery.com/ticket/11575

Using this code with 1.7.2 and edge

$.ajax({

type: 'get',

url: 'http://openapi.ro/api/companies/123456789.json',

dataType: 'jsonp',

success: function(data) {

alert('success 404');

},

error: function(data) {

alert('fail 404')

}

});

$.ajax({

type: 'get',

url: 'http://widgets.membership.s-msft.com/v1/user/usercard/?id=badID',

dataType: 'jsonp',

success: function(data) {

alert('success 500');

},

error: function(data) {

alert('fail 500')

}

});

jsfiddle link:

http://jsfiddle.net/geoffreyk/GTNX8/

The first ajax call is to a page that will return a 404 error code.

The second ajax call is to a page that will return a 500 error code.

I am seeing in the following browsers, all on win7:

FF12:

404 and 500 error functions are NOT called

Chrome 18:

500 error function is NOT called

404 error funciton is called

Chrome 18:

500 error function is NOT called

404 error funciton is called

IE8:

404 and 500 error functions are called

IE9:

404 and 500 error functions are called

Opera 11:

404 and 500 error functions are NOT called

bummer :(

Attachments (0)
Change History (11)

Changed May 01, 2012 08:38PM UTC by geoffreyk comment:1

arr, dropped a br. should be a break between "all on win7: " and "FF12:"

Just to clarify,

All of these tests were on windows 7.

The first test was on FF12.

Changed May 01, 2012 09:04PM UTC by geoffreyk comment:2

One more test

IE7 on Vista:

404 and 500 error functions are called

Changed May 05, 2012 03:57PM UTC by dmethvin comment:3

cc: → jaubourg

This is basically a dup of #10256, but at minimum the docs need some clarification about when the error callback may occur.

For example, it looks to me that the script transport is being used in Chrome and the script tag's .onload() fires even though the script URL is 404. Since there was no actual script content the jsonp callback didn't get called, so the error callback fires since there is no json to parse.

@jaubourg can you weigh in on this? Seems like we can't say the error callback will *not* be called, but only that it isn't called reliably on all browsers.

Changed May 05, 2012 10:16PM UTC by jaubourg comment:4

We can be more precise in the docs but last time I checked onload didn't trigger for chrome in case of a 404. It's more likely that onerror doesn't trigger for a 500.

If people need reliable error handling for jsonp, they'd better use jQuery-JSONP ( https://github.com/jaubourg/jquery-jsonp ) and, if there are bugs there, to open issues against it.

I hope to be able to bring jQuery's jsonp implementation up to speed with the plugin but:

1. it has a cost in size

2. until Opera ticks to a new version, there is sniffing involved

Changed May 08, 2012 11:48PM UTC by geoffreyk comment:5

IMHO, this is exactly what jQuery has always been and should continue to be about. Making difficult things simple and unifying the differences between browsers.

JSONP is not simple to implement, but the interface that jQuery has created makes using it so simple, that there are no reasons not to use it.

Except that to have really robust AJAX, you have to have good error handling. Stuff just breaks on internet, and those errors must be handled.

All smiles and rainbows, except once again, the browsers are handling errors differently. This is where jQuery has always shined. Bringing all the different browser implementations together so that we lowly devs can go out and create great code without worrying about the incompatibilities.

If jQuery is going to provide JSONP, then I believe it also needs to handle errors states correctly too. This should not be handed off to a plug in.

My $0.02

Changed May 08, 2012 11:49PM UTC by dmethvin comment:6

@geoffreyk, looking forward to your patch!

Changed May 09, 2012 12:06AM UTC by geoffreyk comment:7

_comment0: Replying to [comment:6 dmethvin]: \ > @geoffreyk, looking forward to your patch! \ \ I am only qualified to use it, cheerlead for it, but not create it :) \ \ I will give it a look though, but I think it may be over my head... \ 1336522103357427

Replying to [comment:6 dmethvin]:

@geoffreyk, looking forward to your patch!

I am only qualified to use it, cheerlead for it, beg for it, but not create it :)

I will give it a look though, but I think it may be over my lowly head...

Changed May 09, 2012 12:24AM UTC by dmethvin comment:8

This is an open source project, if you want something to happen you can make it happen. We're not opposed to this change at all, just not convinced it can be done given the state of browser support.

Honestly I think you are halfway there. For the browsers that don't yet support error events on script elements, create a non-jQuery test case and file a bug report with them, or find an existing one and vote it up. Then put the links here so they can be easily tracked. The good news is that the older browsers like IE8 do what you want already.

Changed May 11, 2012 05:31PM UTC by dmethvin comment:9

component: unfiledajax
priority: undecidedlow
resolution: → patchwelcome
status: newclosed

To reiterate, we're open to standardizing behavior here but don't think the browser support is able to do it. If someone notices in the future that browsers have cleaned up their act, or thinks up another way to do this, please let us know.

Changed February 21, 2013 01:38PM UTC by guitarsolo92@gmail.com comment:10

$.ajax({

url:'http://maps.googleapis.com/maps/api/geocode/json',

data:{'sensor':'true', 'address':search},

type:'GET',

cache:true,

dataType:'jsonp',

beforeSend: function (jqXHR, settings) {

alert(settings.url); Show-me if is a valid URL, for tests

},

success: function(r) {

alert((r).toSource());

},

error: function (jqXHR, textStatus, errorThrown) {

alert(textStatus + '\\n' + errorThrown);

}

});

Alert Response#1

http:maps.googleapis.com/maps/api/geocode/json?callback=jQuery19107215280201753225_1361453726673&sensor=true&address=rua+araguari+118+bh+mg

Alert Response#2

parsererror

Error: jQuery19107215280201753225_1361453726673 was not called

Whyyy?? i search all the web for that soluction and nobody know!!

Changed February 21, 2013 01:50PM UTC by jaubourg comment:11

Replying to [comment:10 guitarsolo92@…]:

Whyyy?? i search all the web for that soluction and nobody know!!

You need to brush up on those searching skills: http://stackoverflow.com/questions/5359224/parsererror-after-jquery-ajax-request-with-jsonp-content-type