I am working on an application which sends an AJAX POST request (I'm using jQuery currently) every 1500ms. I have noticed that most of the times, these requests succeed within 350-450ms and are sent to the server nicely in the same order as they are generated.
However sometimes, one or two requests take nearly 3-4 seconds and they are delivered later. In my application I need to ensure that these requests are received by the server in the same order as they are sent from the client. How do I do that? I am using currently setInterval of 1500ms to call a function (which generates the data to be posted) and which POSTs it using $.ajax(). However, how do I serialise the requests?
Don't know exactly how this would work out in javascript, but you could create a list or array of your request, first in first out type of list, so when ready you push your request or whatever values needed to create your request into the array, after set interval you take from the array and send request. Basically you'll queue your request that way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With