Abort previous Ajax request

Is it possible to abort a previously executed Ajax request?

var xhr = $.ajax({ type: "POST", url: "some.php", data: "name=John&location=Boston", success: function(msg){ alert( "Data Saved: " + msg ); } }); 
+7
javascript jquery ajax
source share
1 answer

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 ); } }); } }); 
+5
source share

All Articles