sequencing function calls in javascript - are callbacks the only way?

后端 未结 5 547
谎友^
谎友^ 2021-02-03 11:25

I read through various threads like this one for example.

But it really escapes me how to accomplish the following:

I have 4 functions, and want them happen one

5条回答
  •  孤街浪徒
    2021-02-03 12:15

    It's been a while and I noticed something about deferreds in jquery documentation, specifically the when core API function.

    $.when( $.ajax("test.aspx") ).then(function(ajaxArgs){ 
         alert(ajaxArgs[1]); /* ajaxArgs is [ "success", statusText, jqXHR ] */
    });
    

    Code sample taken from http://jqapi.com/#p=jQuery.when

提交回复
热议问题