trigger event after several ajax calls succeeded

为君一笑 提交于 2019-12-02 01:14:10

RxJS will allow you to do this using the ForkJoin operator, this operator takes N observables with a value and creates one observable that fires with an array when all N observables complete.

See Matthew Podwysocki's blog post about this operator: http://codebetter.com/blogs/matthew.podwysocki/archive/2010/04/23/introduction-to-the-reactive-extensions-for-javascript-going-parallel-with-forkjoin.aspx

You should have a look at .ajaxStop().

However, that callback will fire on every single ajax request that completes. So in order to know when your last request completes, you need either to invoke .ajaxStart() aswell, or you need to iterate a global variable for each request you fire and decrement it on .ajaxStop(). If that variable reaches zero, all your request have completed.

If you know how many calls are being made, then set a variable to that number, and decrement it each time an AJAX completion event occurs. When the variable reaches zero, 'SomethingGreat' has happened.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!