Why Is Ajax Call In Window.unonload Never Called?
Solution 1:
I've had this issue before too. Open up the browser console and go to the network tab. Now navigate away from the page. You will see for a quick moment that your ajax request is marked as (canceled)
because the browser cancels the request as you move away.
I've observed this behaviour in google chrome and haven't checked other browsers, but if it doesn't work reliably in one of the most popular browsers then you know this isn't a reliable solution overall.
Basically, there is no reliable way to do this. I've found not even doing the ajax call in window.onbeforeunload
is reliable.
If I were you, I would put an expiry date on your uploaded files and have a cron job that deletes them after the expiry date is reached. Even if window.onunload
worked, it still wouldn't be a reliable solution—for example, when a user's machine unexpectedly shuts down.
Post a Comment for "Why Is Ajax Call In Window.unonload Never Called?"