What are good ways to ensure AJAX requests called in a certain order get the response in the same order?
-
-
Answer:
Cache the responses in a numerically indexed object that corresponds to a a handler index. Determine some form of "readyness" and poll the object for changes to its state. Once the object has reached that "readyness" state, execute the responses in the order that they were indexed.
Rick Waldron at Quora Visit the source
Other answers
While coding a grid based UI for TV listings (at http://tv.burrp.com/scheduler/view.html) I wished the same :). Unfortunately, in a multi-threaded backend there is no guarantee whatsoever on which incoming HTTP request gets executed first. The last request in queue might come back first with a response. There are two possible ways here - Write a simple JS implementation of Queue to stack all the AJAX requests. Fire only when you have received a response for the penultimate one. This also means that you have to use a an AJAX (say XMLHttpRequest) wrapper. This is not what you asked for but might be something worth pondering over - with each AJAX request, you can generate a unique ID on the frontend, send to the server with the request and have it send it back to you in the response. In your frontend you can keep a map of such ID's versus whatever stateful object you want to store against so that you can map the incoming responses (irrespective or order) to these objects.
Avlesh Singh
The jQuery plugin mentioned by looks good. You could also take a look at the IO Queue in YUI http://developer.yahoo.com/yui/3/io/#queue
Juan Ignacio Dopazo
Simone Verzino
Related Q & A:
- What are good ways to save up for an iPod Touch?Best solution by wikihow.com
- What are good ways to promote my website?Best solution by Yahoo! Answers
- What are good ways to get the "Last Second Bid" on eBay successfully?Best solution by ebay.com
- What are some good ways to get rid of sunburn?Best solution by ChaCha
- What are good ways for personal fund raising?Best solution by wiki.answers.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.