I am coding a page that makes two AJAX
requests by using jQuery
, each one to a different server. But the problem is when each requests needs to call to it's own timeout event. It seems that the only timeout event it's fired by the last AJAX
request made. If I just do a single request on the page the timeout works, but if I add a second request the first script's timeout does not work.
I already spent hours searchig about how to fix this with out success.
Here is an example of my code to help you figure out what I am talking about:
$(document).ready(function($) { // This goes in the fist script but I could not put the script tags
function getData() {
$.ajax({
url: "urlpath",
async: false,
dataType: "jsonp",
timeout: 4000, // This timeout does not work when the second request is present
success: function(parsed_json) {
console.log("Success for the fist request");
},
error: function(request, status, err) {
if (status == "timeout") {
console.log("Timeout error for the first request");
} else {
console.log("Unknown error for the fist request");
}
}
});
});
$(document).ready(function() { // This goes in the second script
$.ajax({
url : "urlpath.json",
dataType : "json",
timeout: 8000, // This timeout does work
success: function(parsed_json) {
console.log(Success for the last request);
},
error: function(request, status, err) {
if (status == "timeout") {
console.log(Timeout reached for the last request);
} else {
console.log(Unknown error on the last request);
}
}
});
});
Any help is welcomed. Thank you so much in advance.