wait for two ajax calls code example
Example 1: jquery wait for all ajax requests to complete
$.when(ajaxCall1(), ajaxCall2()).done(function(ajax1Results,ajax2Results){
});
function ajaxCall1() {
return $.ajax({
url: "some_url.php",
success: function(result){
console.log(result);
}
});
}
function ajaxCall2() {
return $.ajax({
url: "some_url.php",
success: function(result){
console.log(result);
}
});
}
Example 2: how to wait till jquery post request has been made
$.when(ajax1(), ajax2(), ajax3(), ajax4()).done(function(a1, a2, a3, a4){
});
function ajax1() {
return $.ajax({
url: "someUrl",
dataType: "json",
data: yourJsonData,
...
});
}