My Main GOAL and actual scenario: If two users share the same credentials, then the second user can not login into the system until the first one who is already logged in, log outs system.
Actually I want to set login_flag=0
on server database, when user closes the browser window. I googled and figured out to send an ajax request before either by
$(window).on('unload', function(){ // ajax here with async:false });
or
$(window).on('beforeunload', function(){ // ajax here with async:false });
It's working fine. But in Chrome, it logs the following message:
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/.
I have googled again for the same and came to know that it is discouraging to use Ajax on unload event, and found following details from here
in short, they are against the use of ajax with async:false
with window.unload
or window.beforeUnload
method. If I remove async
param from Ajax, then it's not working as intended.
What is the right approach if I want to do some activity on server side if user closes browser window?