中止先前正在运行的 Ajax 请求 [重复]

Posted

技术标签:

【中文标题】中止先前正在运行的 Ajax 请求 [重复]【英文标题】:Abort a previous running Ajax request [duplicate] 【发布时间】:2013-12-08 04:03:15 【问题描述】:

是否可以中止以前运行的 Ajax 请求?

var xhr = $.ajax(
    type: "POST",
    url: "some.php",
    data: "name=John&location=Boston",
    success: function(msg)
       alert( "Data Saved: " + msg );
    
);

【问题讨论】:

if(xhr)xhr.abort(); 怎么样? 我认为有可能,它在 ASP.NET AJAX 工具包中可用 感谢所有回答。现在解决了 【参考方案1】:

试试这样的

        $(document).ready(function()
            var xhr; // global object

            function your_function() 
                if(xhr && xhr.readystate != 4)
                    xhr.abort();
                

                xhr = $.ajax(
                    type: "POST",
                    url: "some.php",
                    data: "name=John&location=Boston",
                    success: function(msg)
                       alert( "Data Saved: " + msg );
                    
                );
            
        );

【讨论】:

谢谢,它对我有用。

以上是关于中止先前正在运行的 Ajax 请求 [重复]的主要内容,如果未能解决你的问题,请参考以下文章