You can accomplish this easily with jQuery using the complete callback
var checked = 0;
$(function() {
$.ajax({ url: "1st ajax", complete: function(){ checked++; Check(); }});
$.ajax({ url: "2nd ajax", complete: function(){ checked++; Check(); }});
$.ajax({ url: "3rd ajax", complete: function(){ checked++; Check(); }});
}
function Check() {
if (checked >= 3) {
// all 3 have been successfully completed or timedout
}
}
or using then() deferred object to call the sequentially:
$.get("1st ajax").then(function(){
$.get("2nd ajax").then(function(){
$.get("3rd ajax").then(function(){
// call something
});
});
});
or using then() deferred object to call them without waiting with Check()
method:
$.get("1st ajax").then(function(){ checked++; Check(); });
$.get("2nd ajax").then(function(){ checked++; Check(); });
$.get("3rd ajax").then(function(){ checked++; Check(); });