Due to the way jsonp
requests works, you are not able to find out if a request failed and why.
What you can do is to set a timeout
yourself for the jsonp
request. If you don't get a valid response in that time, the error callback is called.
You need to figure out yourself what value you want to set for the timeout
, because if e.g. the time required for sending the request, building the response and sending it back takes 500ms
and you set the timeout to 100ms
, the error callback will be called all the time, even if the request itself did not timeout.
$.ajax({
url : obj.url,
data : obj.data,
dataType : "jsonp",
jsonp : "callback",
timeout:300,
jsonpCallback: "RequestController.callbackObj.onSuccess"
}).success(function() {
console.log('test')
}).error(function() {
console.log("error");
});