onbeforeunload事件上的jQuery.ajax无法正常工作 [英] jQuery.ajax on onbeforeunload event not working

查看:74
本文介绍了onbeforeunload事件上的jQuery.ajax无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的php页面

I have one php page like this

<script type="text/javascript" src="js/jquery.min.js"></script> 
<script type="text/javascript">
window.onbeforeunload  = saveBeforeExit;
function saveBeforeExit() {  
    jQuery.ajax({
        url:"truncate_logs.php",
        type:"GET",
        async:false,
        success:function(data){

        }
    })
}
</script>

//I am creating 'logs_".$t.".xls' here

<?php
header("Location: log_files/logs_".$t.".xls");
?>

我的问题在这里

Location:onbeforeunload不会被调用.

推荐答案

onbeforeunload无法正常工作,因为编码不正确.您需要从onbeforeunload返回一个字符串,该字符串将用作出现的窗口中的消息.

onbeforeunload is not working because it isn't coded properly. You need to return a string from onbeforeunload , which will be used as the message in the window that will appear.

这篇关于onbeforeunload事件上的jQuery.ajax无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆