为什么 unload 和 beforeunload 不能在 firefox 上运行?有什么解决办法吗?
why unload and beforeunload not working on firefox? is there any solution?
在 Chrome 上它工作正常但在 firefox 上它不工作
function myfoo(){
// Write your logic here
$.ajax({
type: "POST",
url: "update.php",
dataType: 'json',
data: {Eventid: 'Eventid',Seats:'Seats'},
success: function (r) {}
});
}
卸载时window
$(window).on('beforeunload', function () {
return 'Are you sure you want to leave?';
});
卸载时调用函数
$(window).on('unload', function () {
console.log('calling ajax');
myfoo();
});
"onbeforeunload" 和 "unload" 都在工作,但在您的场景中,您希望发送 ajax 呼叫。所以尝试将 ajax asynchronous 更改为 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) {}
});
}
在 Chrome 上它工作正常但在 firefox 上它不工作
function myfoo(){
// Write your logic here
$.ajax({
type: "POST",
url: "update.php",
dataType: 'json',
data: {Eventid: 'Eventid',Seats:'Seats'},
success: function (r) {}
});
}
卸载时window
$(window).on('beforeunload', function () {
return 'Are you sure you want to leave?';
});
卸载时调用函数
$(window).on('unload', function () {
console.log('calling ajax');
myfoo();
});
"onbeforeunload" 和 "unload" 都在工作,但在您的场景中,您希望发送 ajax 呼叫。所以尝试将 ajax asynchronous 更改为 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) {}
});
}