I have multiple ajax queries running at the same time, and I want them to wait for the last one to return, and then run the success handler on all of the ajax calls. For a
This can probably be done in a very similar fashion to what you've already proposed.
First, create global variables var sleep = true
and var request_count = 0
. Then start a timer that checks request_count
against total number of requests every second or so. Then, your success functions can increment request_counter
and then start looping until sleep == false
. Then, when the monitoring function running via timer detects request_count == TOTAL_REQUESTS
it sets sleep = false
, and all your success functions continue about their business at that point.