When I have multiple tabs open of the same website in a browser, I wonder how other windows can detect when a user has logged out. My development setup involves using Python/Django.
The method I am currently implementing is:
function user_checking(){
$.ajax({
url: /check_user_login,
type: 'POST',
success: function (data) {
if (data['user_status'] == 'not_loggedin'){
location.reload();
}
},
error: function (data) {
},
}); //ajax end
}
var validateSession = setInterval(user_checking, 1000);
To monitor whether the user is logged out or not, I am constantly sending the user_checking() function every second. Is this the correct approach?