I tried various options but none seem to work. Finally, I came across one solution, that seem to work perfectly well for my situation.
The idea behind this perfect solution is,
- Bind the "beforeunload" event on the window object.
- In the event handler, set a global variable to indicate that the page is being unloaded.
- In the global Ajax error handler, do not take any action if the above global variable is set.
- In all other cases, perform the actual Ajax error handling.
The code is pretty self explanatory and well documented. That's about all it takes to get the job done!