你可以添加优先AJAX调用 [英] Can you add priorities to AJAX calls

查看:85
本文介绍了你可以添加优先AJAX调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建使用AJAX来获取信息的页面一些插件。现在有不同的插件,做不同的功能。

I am creating some plugins that use ajax to fetch the information for the page. Now there are different plugins that do different functions.

所有的插件必须作为独立的,但我也想补充一点,他们可以很好的协同工作的功能。

All the plugins need to be used as stand-alone, but I also want to add the functionality that they can work nice together.

所有不同的插件,有没有自己的JavaScript文件和功能。这是在HTTP请求方面没有问题,因为大多数人都认为合并所有文件到一个当网站被deplyed插件。

All the different plugins have there own JavaScript file, and functions. This is no problem in terms of HTTP requests, because most people have plugins that merge all the files into one when the website is deplyed.

-

现在我的问题。正如我所说的不同的插件得到网站的不同部分。例如,职位数,用户的微博,用户 - 统计数据,发表评论

Now for my question. As I say the different plugins get different parts of the website. For example, post counts, user tweets, user - statistics, post comments.

现在我可以指定在该信息从网站上被称为优先级。我不能将所有文件合并成一个Ajax调用我想,是因为他们都是各个工作部件。

Now can I specify the priority on which this information is called from the website. I can not merge them all into one ajax call I think, because they are all individual working components.

任何人都知道一个很好的解决方案,我怎么能spicify先拿到的意见,在这之后的统计数据,等等,等等。

Anyone know a good solution how I can spicify to first get the comments, after that the statistics, etc, etc.

我选择的JS框架是jQuery的。

My JS framework of choice is jQuery.

推荐答案

一种通用的方法是实现一个优先级队列挂起AJAX调用。每个插件将使他们的呼叫队列,与该呼叫相关联的优先级,以及AJAX队列处理器将努力通过队列按优先顺序排列。

One general method would be to implement a priority queue for pending AJAX calls. Each plugin would place their call on the queue, with an associated priority on the call, and an AJAX queue processor would work through the queue in order of priority.

下面是一个jQuery的优先级队列插件的例子:

Here's an example of a jQuery priority queue plugin:

http://benalman.com/$c$c/projects/jquery-message-queuing/docs/files/jquery-ba-jqmq-js.html

此外,这里有一个已经实施了AJAX请求:

Also, here's one already implemented for AJAX requests:

<一个href="http://stackoverflow.com/questions/3034874/sequencing-ajax-requests/3035268#3035268">Sequencing Ajax请求

这篇关于你可以添加优先AJAX调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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