I am using JQuery to do an ajax calls to fetch data. I am doing several calls to fetch peices of this data incrementally. So I have something like:
for(i=0;i<numOfDataObjects;i++) {
$.ajax({
//get the data and do something with it in the success callback
});
}
I have some code after this loop that I want executed only after all the ajax calls have completed and the success callbacks exited. Right now this is not happening, I guess because of the asynchronous nature of the xhr object.
Is there a way, without incrementing a global counter in each ajax success function (and checking if it equals a certain value), to ensure that the code after the loop gets executed after all the server calls have completed?