继续中止AJAX(jqXHR)请求

是否可以继续中止AJAX(jqXHR)请求?

就像是:

$(document).ajaxSend(function(event, jqXHR, ajaxOptions) { if(/* it enters my conditions */) { $.current_request = jQuery.extend(true, {}, jqXHR); jqXHR.abort(); } } // some time in the future $.ajax($.current_request) 

这不起作用,我可以看到一个我不知道如何解决的问题:再次发送请求时没有设置任何选项。

试一试(未经测试)

 var request_queue = [], is_processing = false; $(document).ajaxSend(function(event, jqXHR, ajaxOptions){ if(/* it enters my conditions */) { jqXHR.abort(); request_queue.push(ajaxOptions); } else if (request_queue.length && !is_processing) { is_processing = true; while (ajaxOptions = request_queue.shift()) { $.ajax(ajaxOptions); } is_processing = false; } }); 

$.ajax(theoptions)

它们当前存储在ajaxOptions参数中,您必须将其存储在全局某处以便以后访问它(例如在$ .current_request中) – Kevin B