Reputation: 1578
I am making a Nodejs application and I am using jQuery to send ajax request to server side.
Weirdly, the browser will send ajax request for multiple times.
Is this because of no response being returned from server side?
$.ajax({
type: "POST",
url: "/triggerBatchJobs",
data: JSON.stringify(buildInfo),
contentType: 'application/json'
}).done(function(msg){
console.log(msg);
});
I post ajax request by this code snippet, I monitor the network tab in chrome dev tools and found the request stays in pending since there is no response returned from server side.
Will the browser try to send and get response again for these pending request?
BTW, I use socket.io in this application. Is this problem due to socket.io?
script.
var socket = io();
socket.on('complete',function(msg){
alert('Complete');
})
in node.js
io.sockets.emit('complete');
Upvotes: 0
Views: 880
Reputation: 15647
Weirdly, the browser will send ajax request for multiple times.
No, in fact you should do something more complicated to send the request again if an error occurred.
My suggestion is to put a breakpoint in the application $.ajax
and check how many times stops. You may use the stack to know from where the call originates.
Is this because of no response being returned from server side?
No at all, if the request expires, the error callback will be called. (related, related) So, by default there no timeout established.
Try
$.ajax( { ..., timeout:3000 ,... } );
Will the browser try to send and get response again for these pending request?
Again, NO.
I use socket.io in this application. Is this problem due to socket.io?
I guess is unrelated.
Upvotes: 0