1//jQuery waiting for all ajax calls to complete b4 running
2$.when(ajaxCall1(), ajaxCall2()).done(function(ajax1Results,ajax2Results){
3    //this code is executed when all ajax calls are done
4});
5
6function ajaxCall1() {
7    return  $.ajax({
8        url: "some_url.php",
9        success: function(result){
10            console.log(result); 
11        }
12    });
13}   
14
15function ajaxCall2() {
16    return  $.ajax({
17        url: "some_url.php",
18        success: function(result){
19            console.log(result); 
20        }
21    });
22}1$.when(ajax1(), ajax2(), ajax3(), ajax4()).done(function(a1, a2, a3, a4){
2    // the code here will be executed when all four ajax requests resolve.
3    // a1, a2, a3 and a4 are lists of length 3 containing the response text,
4    // status, and jqXHR object for each of the four ajax calls respectively.
5});
6
7function ajax1() {
8    // NOTE:  This function must return the value 
9    //        from calling the $.ajax() method.
10    return $.ajax({
11        url: "someUrl",
12        dataType: "json",
13        data:  yourJsonData,            
14        ...
15    });
16}