I recently got a situation where I need to set a bit in a database from 1 to 0 on web page on close event and I found there is no such event but an unload event so I thought I can generate an AJAX call from it.
Now, when some one tries to close the browser, it should be closed instantly because of UE and if I will have AJAX request that will change a bit from 1 to 0 in database, it would probably be taking a second in my internet connection but some one on the other side can have slow connection and the browser will wait little longer prior to close. Am I right? Or the browser will be hidden and it will carry the AJAX request in the background?
Or if you think any other solution is available that would be helpful.
That is not a reliable way to do this. It’s not guaranteed that the browser will make the request and it can also potentially detrimental to user experience.
Here’s a page with details on better ways to accomplish this:
http://ajaxpatterns.org/Heartbeat