How do I cancel an ajax request that I have not yet received the response from using jquery?
![]() ![]() ![]() 11
|
|||
|
![]() ![]() |
Most of the jQuery ajax methods return an XMLHttpRequest (or ie equivalent) object, so you can just use abort()
|
||||||||||||
|
![]() ![]() |
It's an asynchronous request, meaning once it's sent it's out there. In case your server is starting a very expensive operation due to the AJAX request, the best you can do is open your server to listen for cancel requests, and send a separate AJAX request notifying the server to stop whatever it's doing. Otherwise, simply ignore the AJAX response. |
||
|
![]() ![]() |
You can't recall the request but you can set a timeout value after which the response will be ignored. See this page for jquery AJAX options. I believe that your error callback will be called if the timeout period is exceeded. There is already a default timeout on every AJAX request. |
||
|
![]() ![]() |
meouw's solution is correct, but if your are interested in more control then you could try the ajaxManager plugin for jQuery. |
||
|
![]() ![]() |
Superb solution abort() is working .... jQuery is awesome ... ibrahim ,Hyderabad INDIA |
||
|