0

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');
Chuck
  • 1,508
  • 4
  • 15
  • 19
  • 1
    do you have any code? – webduvet Oct 14 '14 at 15:36
  • Are you sure it is the same request twice, and not two different requests? Wondering if the second request is the browser loading the favicon.ico file. – loganfsmyth Oct 14 '14 at 16:50
  • @loganfsmyth Actually in network tab of chrome, I can only see that request stays in pending. But in my nodejs code in debug mode, the server side api will be called again after seconds. I wonder whether or not the browser will send request again for those pending request – Chuck Oct 15 '14 at 05:32

1 Answers1

0

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.

Community
  • 1
  • 1
rnrneverdies
  • 15,243
  • 9
  • 65
  • 95