Rakesh
Rakesh

Reputation: 5893

Kill an Ajax Request in between

I am firing an Ajax request using jQuery. During the process, I show a loading text to the user till it reaches the success/errorhandler function. Is there a way to abort the request in middle of it. So that it doesn't goes to the success/errorHandler variable. One way I can think of is using a global variable. Is there a better method.

Thanks

Upvotes: 3

Views: 1976

Answers (2)

Jeremy French
Jeremy French

Reputation: 12157

I think you can just call the abort() method of your request object.

It may be more complicated than this depending on the behaviour you are after see here.

Upvotes: 0

Natrium
Natrium

Reputation: 31174

Perhaps is a start?

$.ajax() returns the XMLHttpRequest that it creates. In most cases you won't need that object to manipulate directly, but it is available if you need to abort the request manually.

http://docs.jquery.com/Ajax/jQuery.ajax#options

Upvotes: 4

Related Questions