Suppose I have setInterval(PostToServer, 1000);. PostToServer function makes ajax post, which may take longer than a second. So what happens then: a second call is made while the first hasn’t finished or the end of call is awaited before making new one?
Suppose I have setInterval(PostToServer, 1000); . PostToServer function makes ajax post, which may take
Share
The calls overlap.
setIntervalensures that the functions are run regularly, without waiting for the previous result.If you want to await the response, change the interval method to a poller. When the time has passed AND the server has already responded, request again.
Since the server response won’t change too much right after the response, you can also add a
setTimeouthandler in the callback function of your AJAX method.