Having a really hard time with this issue, and I know $.when() can be used like so (with multiple AJAX statements) to promise you when they have all finished.
$.when(
$.ajax({ url: '/echo/html/', success: function(data) {
alert('request 1 complete')
}
}),
$.ajax({ url: '/echo/html/', success: function(data) {
alert('request 2 complete')
}
})
).then( function () { alert('all complete'); });
But this only works with raw $.ajax(), is there anyway to have this same functionality with function calls, that in turn have the ajax inside them (and other random logic) ?
Pseudo-code idea:
// The functions having the AJAX inside them of course
$.when(ajaxFunctionOne, ajaxFunctionTwo).then(function () {
alert('all complete');
});
$.when()is the return value of the function calls made to$.ajax; you're not passing it functions, in other words. By the time that$.when()is called, the ajax operations have already started.