1

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

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

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

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

function useajax()
{
    $.ajax(...)
}
user1123379
  • 334
  • 3
  • 5
  • 13
  • possible duplicate of [Kill Ajax requests using JavaScript using jQuery](http://stackoverflow.com/questions/446594/kill-ajax-requests-using-javascript-using-jquery) – James Montagne Feb 24 '12 at 18:29

1 Answers1

3

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

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

$(".stop").click(function(){ jqXHR.abort(); });
jrummell
  • 42,637
  • 17
  • 112
  • 171