Can you tell me why this doesn't work..?? also tried with window.unload but it also didn't worked
window.onbeforeunload = function(){
$.ajax({
url:'logout.php',
type:'POST',
data:{user:$("#user").val()},
success: function(response){
alert(response);
}
})
}