6

I'm using jquery for making ajax requests

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

How can I manually stop my particular ajax request?

2
  • 1
    possible duplicate: stackoverflow.com/questions/446594/… Commented Feb 21, 2012 at 8:29
  • ok, thank you. I failed to find it after some hard googling Commented Feb 21, 2012 at 8:31

2 Answers 2

22

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(); 
Sign up to request clarification or add additional context in comments.

4 Comments

ajax can be stopped from being initiated, but once its made its not possible to stop it...
@JIA, you can abort the AJAX request in the browser but of course if it has already hit the web server, that's a whole different story. The web server will continue to execute the request. It's just that since the browser aborted the request the web server will send the response to the void.
@DarinDimitrov so it means that if an already initiated request is aborted using the .abort method it will not be catered for at the client side ...
@JIA, that will depend when you call the abort method.
3

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.

1 Comment

XHR requests, like all HTTP requests, can be aborted while underway. Whether a certain Ajax library exposes this functionality is a different issue.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.