I'm using jquery 1.7.2 for some ajax call onloud of an aspx page. ajax calls webservice methods . if user push refresh button or click on some menu to redirect to another page when ajax calls still in progress and not success yet, an error shown in firebug console that not make sense. what can i do to kill ajax pending requests when user try to leave the page?
Asked
Active
Viewed 2,122 times
0
-
surely you will find your answer here: http://stackoverflow.com/questions/446594/kill-ajax-requests-using-javascript-using-jquery – Ashwini Verma May 17 '12 at 05:57
1 Answers
-1
you can do this for instance it your ajax calling function
var call = $.ajax({
type: "POST",
url: "mywebservice.aspx",
data: "some data you are passing ",
success: function(msg){
// do stuff on sucess
}
});
and the you can call this to kill the process.
call.abort()

COLD TOLD
- 13,513
- 3
- 35
- 52
-
Thanks , but when should i call abort if i wanna kill process before page unload ? – Hossein Rahmani May 17 '12 at 05:51
-
whenever you redirect the page you must have a button or a link so as you click the link you should execute abort – COLD TOLD May 17 '12 at 05:53
-
-
-
I want to kill alive ajax calls if user not wait for success and leave the page in one of this ways : refresh the page , click on some menu to redirect to another page. – Hossein Rahmani May 17 '12 at 06:00
-
on the refresh you might check if the ajax content in ad div is fully loaded if not than kill it and for menu click just kill the call when it cliked – COLD TOLD May 17 '12 at 06:09