views:

640

answers:

3

Hi, 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

+4  A: 

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

Natrium
A: 

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.

Jeremy French