0
我需要關閉用戶會話與AJAX,當這關閉我的應用程序的導航或選項卡。爲此,我使用beforeunload事件,問題是當我用F5(cmr + r,ctrl + r)重新加載頁面時,用這個nav打開警告診斷,我不需要這個。事件之前卸載
$(window).bind('beforeunload',function (e) {
var message = 'Are you sure you want to leave?';
return message;
}
$(window).bind('unload', function() {
var dataStatus = $('button[name="status"]').attr('data-status');
if (dataStatus == 'online') {
var req = $.ajax({
url: 'mi-url',
type: 'POST',
async : true,
data: {data: JSON.stringify({user_id: <?php echo $user->getId() ?>})},
dataType: "JSON"
});
}
});
等待回信,謝謝。
可能的重複:http://stackoverflow.com/questions/5606331/how-to-prevent-calling-onbeforeunload-when-page-refresh – Kaiido