Wait until all jQuery Ajax requests are done?

后端 未结 21 1841
离开以前
离开以前 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:35

    Use the ajaxStop event.

    For example, let's say you have a loading ... message while fetching 100 ajax requests and you want to hide that message once loaded.

    From the jQuery doc:

    $("#loading").ajaxStop(function() {
      $(this).hide();
    });
    

    Do note that it will wait for all ajax requests being done on that page.

提交回复
热议问题