I have this so far
window.addEventListener("beforeunload", function(e){
$.post('insert.php', {'postmessage':'CALL bor.update_records_exit(\'' + authUser + '\');'}, function(data) {
e.returnValue = null;
return null;
})
.fail(function(response) {
alert('Error: ' + response.responseText);
});
});
This is working but not reliably. Sometimes the request is sent, sometimes it isn't and I don't understand why.
I know that it has something to do with the synchronicity of the request. I tried using .ajax() instead and setting async property to false, but then i realized that async:false has been depracated.
All i need to do is send a final insert query when the user closes the browser or the tab... Please help.