Reputation: 98
Below is my code
var tweetid = '133450847156838400';
$.ajax({
dataType: "jsonp",
url: "http://api.twitter.com/1/statuses/show/"+tweetid+".json?include_entities=1&callback=?",
error:function(xhr, testStatus, error) {
alert("error");
},
success: function(html){
alert("success");
}
});
Chrome console shows me 404 error response but jQuery is not able to trigger the alert.
I added
$(document).ajaxError(function(event, request, settings){
alert('error');
});
nothing happens. Can someone help me in handling this error as I have to detect if this tweet is deleted.
Upvotes: 3
Views: 473
Reputation: 40582
The jQuery.fn.ajax() page explains that error: fxn()
is not called when using jsonp. Here is the blurb:
Note: This handler is not called for cross-domain script and JSONP requests. This is an Ajax Event.
The only solution I've heard of in this case is to utilize a proxy, which circumvents the same origin policy and allows you to utilize error callbacks. I've never tried this, though, and don't feel qualified to give you advice on how to do it ;)
Upvotes: 1
Reputation: 6375
I'm pretty sure (not entirely), that the dataType jsonp doesn't properly handle non-200 http status codes. The reason is on jsonp actually works. The wikipedia page explains it better: http://en.wikipedia.org/wiki/JSONP, but basically, jsonp amounts to appending a script element onto the page with the url you've given. And the body of the script element is a function call. If you get any status code != to 200, then that body will not be there and no function will be called (which eventually calls the callback functions).
So, if you continue to use jsonp, then you will need to have some kind of timeout in waiting for a response and expect that the request failed or some other method.
Upvotes: 2