Chaining ajax requests with jQuery's deferred

后端 未结 7 2368
天涯浪人
天涯浪人 2021-02-19 19:46

I have a web app which must call the server multiple times. So far, I had a long nested callback chain; but I would like to use jQuery\'s when,then etc

7条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-19 20:22

    My way is to apply callback function:

    A(function(){
           B(function(){
                C()})});
    

    where A, B can be written as

    function A(callback)
    $.ajax{
        ...
        success: function(result){
            ...
            if (callback) callback();
       }
    }
    

提交回复
热议问题