Is it possible to abort a previously-running Ajax request?
var xhr = $.ajax({
type: "POST",
url: "some.php",
data: "name=John&location=Boston",
success: function(msg){
alert( "Data Saved: " + msg );
}
});
Just use ajax.abort(); } //then you make another ajax request $. ajax( //your code here );
}); If isLoading is false, the AJAX call starts, and we immediately change its value to true. Once the AJAX response is received, we turn the value of that variable back to false, so that we can stop ignoring new clicks.
abort() method aborts the request if it has already been sent. When a request is aborted, its readyState is changed to XMLHttpRequest.
processData: It's default value is true. It is used to specify whether or not data sent with the request should be transformed into a query string.
try something like this
$(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 );
}
});
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With