经过多次Ajax调用触发事件成功事件、Ajax

2023-09-10 14:28:58 作者:分手、随缘

我不知道这是触发经过数(无序)的Ajax调用完成事件的最佳方法。

I wonder which is the best approach to trigger an event after several (unordered) ajax calls finished.

要使它更清楚一点,我想调用一个方法doSomethingGreat(),它会触发一些Ajax调用,在那些成功的插件不必要的顺序。我只想触发事件SomethingGreatFinished当所有这些呼叫的成功。我也不想链的这些要求,因为那将是缺乏性能是完全反对的异步编程的想法。

To make it a bit clearer, I would like to call a Method doSomethingGreat() which triggers several ajax calls, the order in which those succeed ins unnecessary. I just want to trigger an event 'SomethingGreatFinished' when all of those calls succeeded. I also don't want to chain these calls, because that would be lacking performance and would be totally against the idea of asynchronous programming.

我不知道一个。)有一个共同的模式为,B)。这可能与无功扩展对JavaScript(RxJs)或C来完成。)与本地jQuery的特点。

I wonder if a.) there is a common pattern for that, b.) this can be done with the Reactive Extensions for JavaScript (RxJs) or c.) with native jquery features.

任何帮助是AP preciated!

Any help is appreciated!

推荐答案

RxJS将让你这个用ForkJoin运营商做的,该运营商占据N观测量一个值,并创建一个可观察的火灾与阵列时,所有的N个观测完成了。

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.

请参阅有关该运营商马修Podwysocki的博客文章:http://$c$cbetter.com/blogs/matthew.podwysocki/archive/2010/04/23/introduction-to-the-reactive-extensions-for-javascript-going-parallel-with-forkjoin.aspx

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