jquery如何停止$。单击按钮时的ajax

时间:2022-06-28 20:34:02

How can I stop him in the $.ajax() function when you click on this button:

当您单击此按钮时,如何在$.ajax()函数中阻止他:

<button class="stop">Stop</button>

There is any function that cause to $.ajax() stop?

有任何函数导致$.ajax()停止吗?

Note: My $.ajax script is found in a function, for example:

注意:我的美元。ajax脚本是在函数中找到的,例如:

function useajax()
{
    $.ajax(...)
}

1 个解决方案

#1


3  

$.ajax() returns a jqXHR, which has an abort method.

$.ajax()返回一个jqXHR,它有一个abort方法。

var jqXHR;
function useajax()
{
    jqXHR = $.ajax(url, data, function() { /* complete */});
}

$(".stop").click(function(){ jqXHR.abort(); });

#1


3  

$.ajax() returns a jqXHR, which has an abort method.

$.ajax()返回一个jqXHR,它有一个abort方法。

var jqXHR;
function useajax()
{
    jqXHR = $.ajax(url, data, function() { /* complete */});
}

$(".stop").click(function(){ jqXHR.abort(); });