几次ajax调用成功后触发事件 [英] trigger event after several ajax calls succeeded

查看:133
本文介绍了几次ajax调用成功后触发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在几个(无序)的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的反向扩展(RxJ)或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.

任何帮助是赞赏!

推荐答案

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.

请参阅Matthew Podwysocki关于此运算符的博客文章: http:// codebetter。 COM /博客/ matthew.podwysocki /存档/ 2010/04/23 /引进到了无功扩展换javascr ipt-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

这篇关于几次ajax调用成功后触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆