How to wait until nested async jQuery AJAX requests have finished?

后端 未结 2 955
傲寒
傲寒 2020-12-18 07:05

I\'m using jQuery and I have a loop of asynchronous AJAX requests. I know I can wait for them all to be finished by using the handy \'$.when.apply(array_of_requests).then()\

2条回答
  •  执笔经年
    2020-12-18 07:57

    Take a look at $.Callbacks in 1.7. I think you'll be excited about the flexibility of making your own "flows" and the ability to reuse them, run once, etc.

    There's nothing wrong with what you did (the apply pattern may not be a first choice of most, they usually just list them in a $.when(a, b, c....)--but you may like the syntax of $.Callbacks better.

提交回复
热议问题