Run two functions with Ajax calls sequentially

前端 未结 5 1725
难免孤独
难免孤独 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:25

    Allow a function to accept a callback param to be executed when done, and send b function as a callback:

    function c(){
      a(b); 
    }
    
    function a(callback){ 
      $.ajax({
        url: "url_a",
        type: "post",
        dataType: "html",               
        cache: false,
        success: function(data){             
          callback() // Note here call the next function
        },
        error:function(){             
    
        }   
      });   
    }
    

提交回复
热议问题