如何使在jQuery的Ajax请求批? [英] How can I make batches of ajax requests in jQuery?

查看:105
本文介绍了如何使在jQuery的Ajax请求批?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何做的N组Ajax调用。

I'm wondering how to make ajax calls in groups of n.

下面是我用例:

我有一个显示使用量数据的表。您可以深入到每个行,如果每行都有你可以深入更深入到一个共同的属性,你可以选择深入到所有这些一次。对于每一行,一个Ajax调用,以获取附加到表中的数据。

I have a table that displays usage data. You can drill into each row, and if each row has a common attribute you can drill deeper into, you can choose to drill into all of them at once. For each row, an ajax call is made to fetch the data to be appended to the table.

在某些情况下,可以有多达50行到钻入同时。你可以想像,这使一个很大的压力在服务器上。我如何最好地发送小批量的等待批这些调用之前,他们解雇了?

In certain cases there can be up to 50 rows to drill into simultaneously. As you can imagine, that puts a lot of stress on the server. How best can I send these calls in smaller batches that wait on the batch before them to fire off?

我知道有像jQuery插件的消息队列,可以潜在地帮助我,但是这​​是一个工作项目,所以我们想避免尽可能多的插件。

I know there are plugins like jquery message queuing that could potentially help me out, but this is a work project so we'd like to avoid plugins as much as possible.

推荐答案

您可以先看看使用 jQuery.when ,它允许您执行的回调函数,当所有请求已经完成。

You can take a look at using jQuery.when, which allows you to execute callback functions when all requests have completed.

$.when($.ajax("request1"), $.ajax("request2"), $.ajax("request3"))
 .done(function(data1,  data2, data3){
         // Do something with the data
 });

$.when($.ajax("request1"), $.ajax("request2"), $.ajax("request3"))
.then(successCallback, errorHandler);

请参阅下面的帖子了解更多信息。

See the following post for more information.

另外,我不知道这对使用插件,你的AP prehension应受,你是在工作环境中,尤其是如果它可以简化您的工作的事实。因此,允许的工作效率。当然,你必须仔细选择你的插件,因为质量和长期维护可能是一个问题。

Also, I'm not sure that your apprehension towards using a plugin should be affected by the fact that you are in a work environment, especially if it simplifies your work. Hence allowing to be more productive. Granted you have to choose your plugins carefully, since quality and long term maintenance can be a issue.

这篇关于如何使在jQuery的Ajax请求批?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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