Corey Frang在stackoverflow上发布了一个有用的插件,用于排队ajax请求。就我而言,用“大块”加载大量数据是非常有用的,以减少用户感知的慢度。除非在ajax请求的队列完成之前触发分页事件,否则这种情况完美地起作用,在这种情况下,持有加载对象的容器将清除,但排队的请求将继续运行,从而导致不希望的行为。我想要的是找到/学习清除所有现有请求队列的方法。开发人员发布了一种方法来执行此操作,但它似乎不起作用。我试着在jQuery网站上阅读.queue,但我似乎无法理解如何使这项工作。我已经花了很多时间来解决这个问题,但也许我对jQuery的一些更复杂的方面的熟悉程度让我难以接受。希望有人在那里谁更熟悉的jQuery能帮助:)(标记什么建议并没有出现一些工作“!!!!!”)jQuery“队列”(ajaxQueue插件) - 如何清除?
/*
* jQuery.ajaxQueue - A queue for ajax requests
*
* (c) 2011 Corey Frang
* Dual licensed under the MIT and GPL licenses.
*
* Requires jQuery 1.5+
*/
(function($) {
// jQuery on an empty object, we are going to use this as our Queue
var ajaxQueue = $({});
$.ajaxQueue = function(ajaxOpts) {
var jqXHR,
dfd = $.Deferred(),
promise = dfd.promise();
// queue our ajax request
ajaxQueue.queue(doRequest);
// add the abort method
promise.abort = function(statusText) {
// proxy abort to the jqXHR if it is active
if (jqXHR) {
return jqXHR.abort(statusText);
}
// if there wasn't already a jqXHR we need to remove from queue
var queue = ajaxQueue.queue(),
index = $.inArray(doRequest, queue);
if (index > -1) {
queue.splice(index, 1);
}
// and then reject the deferred
dfd.rejectWith(ajaxOpts.context || ajaxOpts,
[ promise, statusText, "" ]);
return promise;
};
// run the actual query
function doRequest(next) {
jqXHR = $.ajax(ajaxOpts)
.then(next, next)
.done(dfd.resolve)
.fail(dfd.reject);
}
return promise;
};
// !!!!!!!!!!!!!!!!!
// this is what the developer suggested on his website in the comments section
// ... but it does not appear to work
$.ajaxQueue.stop = function(clear) { ajaxQueue.stop(clear); }
})(jQuery);
的....? – Luceos 2012-07-24 12:15:55
不完整的问题? :) – Dipak 2012-07-24 12:16:04
我的坏家伙 - 意外地在输入标签时点击“输入”键,现在将其他标签贴出:) – Eva 2012-07-24 12:23:15