ProAnswers.org

How do I cancel an ajax request that I have not yet received the response from using jquery?

How do I cancel an ajax request that I have not yet received the response from using jquery?

1 Like

Most of the jQuery ajax methods return an XMLHttpRequest (or ie equivalent) object, so you can just use abort()
msdn docs
MDC docs

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

//kill the request
xhr.abort()

As of jQuery 1.5 the returned object is a wrapper for the native xhr object called jqXHR. This object appears to expose all of the native properties and methods so the above example still works.
jqXHR docs