Reputation: 251
Is it possible to stop all the requests/scripts that are happening on a page, when the refresh button is hit?
I have a $.ajax request that takes a few minutes. I have tried to do window.stop() in the unload event; I have tried xhr = $.ajax(...); and xhr.abort(); and any other methods found over the internet and nothing works.
Is this even possible? Why the browser still waits for that request to finish and send back a response and not refresh the page?
LATER EDIT (SOLVED): it seems that the waiting problem is actually from the server. If in the ajax call, the script uses the SESSION then the web page will freeze until the request is finished, even if we abort the xhr.
Why is that? Explanation:
Session data is usually stored after your script terminated without the need to call session_write_close(), but as session data is locked to prevent concurrent writes only one script may operate on a session at any time. When using framesets together with sessions you will experience the frames loading one by one due to this locking. You can reduce the time needed to load all the frames by ending the session as soon as all changes to session variables are done.
Upvotes: 0
Views: 4138
Reputation: 571
Maybe try canceling right before refresh as in here?
window.onbeforeunload = function(event) {
xhr.abort();
};
Upvotes: 5