I have an ajax call as follows-
this.send({
url : AppConstants.variables.callURL.feed,
data : rqStr,
onSuccess : function(data, textStatus) {
console.log(textStatus);
});
send : function(obj) {
this.callbackObj = obj;
FeedBackPanel.add(obj.url + "->" + obj.data);
$.ajax({
url : obj.url,
data : obj.data,
dataType : "jsonp",
jsonp : "callback",
jsonpCallback: "RequestController.callbackObj.onSuccess"
});
}
It works fine>however i am trying to provide a wrong domain and in that case i get a
Status Code:504 Gateway Time-out
in the chrome network developer panel.However,Console.log doesn't give me that status.So is there any way i can catch the status code,so that i can take appropriate actions.
My code is working fine..I just need to catch the 504 Gateway Time-out message.Plz help.
I have an ajax call as follows-
this.send({
url : AppConstants.variables.callURL.feed,
data : rqStr,
onSuccess : function(data, textStatus) {
console.log(textStatus);
});
send : function(obj) {
this.callbackObj = obj;
FeedBackPanel.add(obj.url + "->" + obj.data);
$.ajax({
url : obj.url,
data : obj.data,
dataType : "jsonp",
jsonp : "callback",
jsonpCallback: "RequestController.callbackObj.onSuccess"
});
}
It works fine>however i am trying to provide a wrong domain and in that case i get a
Status Code:504 Gateway Time-out
in the chrome network developer panel.However,Console.log doesn't give me that status.So is there any way i can catch the status code,so that i can take appropriate actions.
My code is working fine..I just need to catch the 504 Gateway Time-out message.Plz help.
Share Improve this question asked Dec 31, 2013 at 10:06 Mayur BuragohainMayur Buragohain 1,6151 gold badge25 silver badges46 bronze badges 3-
By
catching the status code
I mean just obtain the 504 value.I have my own mechanism to deal with it. – Mayur Buragohain Commented Dec 31, 2013 at 10:08 -
2
You need an error callback, but as it is a cross domain request using
jsonp
you can only find out that the request had a timeout but you cannot figure out the status code due the wayjsonp
requests work. – t.niese Commented Dec 31, 2013 at 10:11 - how do i find out it had a timeout programatically? – Mayur Buragohain Commented Dec 31, 2013 at 10:13
1 Answer
Reset to default 5Due 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");
});