Run two functions with Ajax calls sequentially

前端 未结 5 1672
难免孤独
难免孤独 2021-01-26 09:52

I have two functions which has ajax calls inside them.

function a(){
    ajaxCall_A();
}
function b(){
    ajaxCall_B();
}

And I

5条回答
  •  攒了一身酷
    2021-01-26 10:35

    You need to synchronize both of them using a semaphore

    function c(){
        $semaphore=true;
        a();
        while($semaphore ) { 
             setTimeout("checksemaphore()", 500);
        } 
        b();
        // expectation : function 'b' will get executed only after function 'a' finished it's execution  
    }
    
    
    inside the ajax call to a
    add a complete: 
    
    complete : function(result) { 
                $waitsemaphore= 0 ; },
    error: function(result) {alert("AJAX completed w/error");alert(result);},
    

提交回复
热议问题