如何实现使用jQuery一个Ajax请求队列 [英] How to implement an ajax request queue using jQuery

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

问题描述

什么是实现使用jQuery Ajax请求队列的最佳方法是什么?具体而言,我想完成以下任务:

What is the best way to implement an Ajax request queue using jQuery? Specifically, I want to accomplish the following:

  • 一个用户触发任意数量在网页中的Ajax请求,这需要进行排队,依次提交的。

  • A user triggers any number of Ajax requests within a web page, which need to be queued up and submitted sequentially.

该网页需要从服务器接收响应,并相应地调整自己。

The web page needs to receive responses from the server and adjust itself accordingly.

最后,如果发生错误(连接丢失,服务器无法响应等),我想jQuery来调用JavaScript函数。

Finally, if an error occurs (connection lost, server failed to respond, etc.), I want jQuery to invoke a JavaScript function.

我挣扎,特别是最后一个要求,如jQuery的Ajax函数的错误处理机制还不是很直观。是否有任何的例子/教程,可以帮助我完成这个任务?

I'm struggling with the last requirement in particular, as the error handling mechanism in jQuery's Ajax functions is not very intuitive. Are there any examples/tutorials that could help me with this task?

谢谢!

推荐答案

我做了一些缓冲这样。一些例子可以发现简单的任务缓冲区和<一href="http://stackoverflow.com/questions/5505828/how-do-you-attach-callbacks-to-the-deferred-object-that-is-attached-to-a-deferred">deferred项目队列。

I've made a few buffers like this. Some examples can be found simple task Buffer and deferred item queue.

对于错误处理,你可以随时使用 .ajaxError

As for error handling you can always use .ajaxError

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

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