i have a php web application, where i use an authentication method. I have a script logout.php in the same directory as the index file. I want that the code in the logout.php be executed if the used mid session decides to exit or navigate away from the page.
ive tried using
function closeIt()
{
var exit = confirm("Are you sure you want to end this chat session ?");
if(exit==true){
$.ajax({
type: "GET",
url: "logout.php",
success: function(){ alert("Done");}
});
}
}
window.onbeforeunload = closeIt;
i get the confirm box, but i am not getting success, am i doing somethign worng or do i need a new approach all together ?