I need to add some codes before close browser tab/windows, or refresh browser. for example i need send students activity scores to database and stop all running timers if needed and also show an alert to students to show scores that they got.i used 'beforeunload' but it don't work for me
$(window).bind('beforeunload', function(e){
$.ajax({
type:'POST',
url: 'increaseScore.php',
data: {personal_code: "414896521", lScore: 85},
success: function(response) {
alert("you have " + response + "Scores, now"); // show scores alert
}
}).promise().done(function() {
clearInterval(); // clear all timers
})
})
what is the way for do this actions before close the browser tab or reload browser? thanks a lot