call function after all ajax requests complete code example

Example 1: jquery wait for all ajax requests to complete

//jQuery waiting for all ajax calls to complete b4 running
$.when(ajaxCall1(), ajaxCall2()).done(function(ajax1Results,ajax2Results){
    //this code is executed when all ajax calls are done
});

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: loading page for all ajax call in jquery 3.3.1

$(document).ajaxStart(function () {
            $('#ajax-loading-image').css("display", "block");
        });
        $(document).ajaxStop(function () {
            $('#ajax-loading-image').css("display", "none");
        });