Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop ajax request

I'm using jquery for making ajax requests

$.ajax(
    url: "http://someurl.org",
    success: function() { ... }
);

How can I manually stop my particular ajax request?

like image 266
tsds Avatar asked Feb 21 '12 08:02

tsds


2 Answers

The $.ajax() method returns an object that could be used to do that:

var xhr = $.ajax(
    url: "http://someurl.org",
    success: function() { ... }
);

and then later when you want to stop the request:

xhr.abort();
like image 70
Darin Dimitrov Avatar answered Sep 20 '22 11:09

Darin Dimitrov


ajax requests are HTTP transactions once made cannot be stopped. You can stop ajax request from being initiated but not kill the already made request.

like image 42
JIA Avatar answered Sep 16 '22 11:09

JIA