Wait until all jQuery Ajax requests are done?

后端 未结 21 1805
离开以前
离开以前 2020-11-21 04:39

How do I make a function wait until all jQuery Ajax requests are done inside another function?

In short, I need to wait for all Ajax requests to be done before I exe

21条回答
  •  梦谈多话
    2020-11-21 05:16

    javascript is event-based, so you should never wait, rather set hooks/callbacks

    You can probably just use the success/complete methods of jquery.ajax

    Or you could use .ajaxComplete :

    $('.log').ajaxComplete(function(e, xhr, settings) {
      if (settings.url == 'ajax/test.html') {
        $(this).text('Triggered ajaxComplete handler.');
        //and you can do whatever other processing here, including calling another function...
      }
    });
    

    though youy should post a pseudocode of how your(s) ajax request(s) is(are) called to be more precise...

提交回复
热议问题