On Chrome its working properly but on firefox its not working
function myfoo(){
// Write your logic here
$.ajax({
type: "POST",
url: "update.php",
dataType: 'json',
data: {Eventid: 'Eventid',Seats:'Seats'},
success: function (r) {}
});
}
When unloading window
$(window).on('beforeunload', function () {
return 'Are you sure you want to leave?';
});
when unloading call function
$(window).on('unload', function () {
console.log('calling ajax');
myfoo();
});
Both "onbeforeunload" and "unload" is working but in your scenario you are expecting to send ajax call. so try changing ajax asynchronous to false.
function myfoo(){
// Write your logic here
$.ajax({
type: "POST",
url: "update.php",
dataType: 'json',
async: false,
data: {Eventid: 'Eventid',Seats:'Seats'},
success: function (r) {}
});
}