简体   繁体   English

继续中止的AJAX(jqXHR)请求

[英]Continue an aborted AJAX (jqXHR) request

Is it possible to continue an aborted AJAX (jqXHR) request? 是否可以继续中止的AJAX(jqXHR)请求?

Something like: 就像是:

$(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)

This is not working, and I can see one problem that I do not know how to solve: no options are set when sending the request again. 这是行不通的,并且我看到一个我不知道如何解决的问题:再次发送请求时未设置任何选项。

Give it a try (not tested) 试试看(未经测试)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM