You can use jQuery.when to wait for multiple ajax calls to complete:
$.when( $.ajax( { url: "/page1" } ), $.ajax( { url: "/page2.php" } ) )
.then( myFunc, myFailure );
If you do not know how many ajax requests there will be you can push them in an array and then invoke jQuery.when via the apply
method:
var requests = [];
requests.push($.ajax({ url: "page1" });
requests.push($.ajax({ url: "page2" });
requests.push($.ajax({ url: "page3" });
$.when.apply(null, requests).then(success, failure);