I have a very unique setup, which I imagine is having some effect on this issue (which I've never seen before).
I'm writing a Google Chrome Extension, and I'm relying on Node.js as my backend.
When I run multiple Ajax requests, and Node.js takes a long time to respond (for instance, 2.5 seconds) some of the Ajax requests will never receive the response and throw an error.
I've set up a test function in my Node.js server that will respond with a JSON object after waiting for 2500 ms. I've confirmed this works with a single request.
Then, I've tried embedding jQuery in the Extension and trying two requests:
(function(){
$.ajax({
url : url,
data : params,
type : "POST",
success : function(data){
alert('success1');
},
error : function(xmlhttprequest, textstatus, message) {
alert('error');
}
});
})();
(function(){
$.ajax({
url : url,
data : params,
type : "POST",
success : function(data){
alert('success2');
},
error : function(xmlhttprequest, textstatus, message) {
alert('error');
}
});
})();
In this case, only the second alert is called. The first one will eventually result in an error (timeout).
I also tried without jQuery, like so:
var xhr = new XMLHttpRequest();
xhr.open("POST", url, true);
xhr.onreadystatechange = function() {
alert('response1');
}
xhr.send();
var xhr2 = new XMLHttpRequest();
xhr2.open("POST", url, true);
xhr2.onreadystatechange = function() {
alert('response2');
}
xhr2.send();
In this case, both of the requests fail; I don't receive a response from either one.
I've also tried this code in a background script, running on an auto generated background page. This also fails (neither success works).
I'm guessing this is related in some way to the very niche case I'm writing here, but at this point I'm really at a standpoint as to how to troubleshoot and move forward. Any ideas for exploring this issue further?
Thanks! Kevin