jQuery Abort Ajax Request – abort() is used to cancel the ajax request. abort() method cancels the requests that has been already sent. Here in this tutorial we are going to explain how you can use abort() method to cancel the ajax request in jQuery.
jQuery Abort Ajax Request : Kill / Cancel Ajax Request
You can cancel the ajax request simply using the abort() method as below –
jQuery Abort Ajax Request : Cancel Ajax Request Example
var ajaxReq = $.ajax({ type: "POST", url: "server.php", data: "email=kelly@yopmail.com&phone=123", success: function(data){ alert( data ); } }); //Now cancel the ajax request ajaxReq.abort(); |
The above example shows a sample ajax request. ajaxReq.abort(); will kill the current ajax request. You can use this function to cancel the ajax requests which has been sent.