How to cancel Ajax requests using jQuery

Share

Since XMLHttpRequest ,or the equivalent, object is returned by jQuery, so you can simply use abort function. To cancel ajax requests you have to follow below code.

var myRequest= $.ajax({
    type: "POST",
    url: "file.php",
    data: "name=you&class=10",
    success: function(e){
       alert( "Awesome : " + e);
    }
});

//Cancel the request
myRequest.abort();

That’s it 🙂

  • May 9, 2014
8 Best Free Stock Video Websites for Tiktok, Reels, and Shorts Top 5 PHP Frameworks: Fast and Secure