The trick is to use callbacks. You make one ajax call, and with its success callback you make the next one.
To do this, simply add them all to the queue and wrap around it, which sends them one at a time.
I wrote once a few days ago. I will show you the implementation in a second.
Sorry for the code wall. Just implement your own task and handler. The buffer will work until the handler calls the second argument (callback) when it finishes processing the task.
Then just pass it the task and handler. The handler executes ajax and calls the callback from the buffer when ajax returns.
In your specific example, if your download takes a long time, it will take a long time to load all 30. The ajax point is for the server to do the material in parallel.
In your case, a much better solution is to make 30 requests and then catch the results and make sure that the results of your ajax calls are only added to dom in order. This is due to the use of $ .ajax and the addition of order tracking.
Thus, the server will do this as quickly as possible, and you will be able to download it as soon as you receive it. Alternatively, if your actions are performed quickly, then their order in the buffer is not fined.
Raynos
source share