通过阿贾克斯卸载运行PHP [英] Running a PHP through Ajax on Unload

查看:191
本文介绍了通过阿贾克斯卸载运行PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有一个PHP脚本运行时,用户离开该页面。这是我使用的是什么目前:

I'm trying to have a php script run when the user navigates away from the page. This is what I'm using currently:

function unload(){
var ajaxRequest;  // The variable that makes Ajax possible!

try{
    // Opera 8.0+, Firefox, Safari
    ajaxRequest = new XMLHttpRequest();
} catch (e){
    // Internet Explorer Browsers
    try{
        ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try{
            ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e){
            // Something went wrong
            window.location = "unsupported.html";
            return false;
        }
    }
}

ajaxRequest.open("GET", "ajax/cancelMatch.php", true);
ajaxRequest.send(null); 
}

通过萤火,看起来它是调用ajaxRequest对象的开放的功能,但PHP不运行!这是什么做的事实,它是在页面的卸载调用它?

Through FireBug, it looks like it is calling the open function of the ajaxRequest Object, but the PHP doesn't run! Is this something to do with the fact that it's calling it on the unload of the page?

另外,我发现所谓的onbeforeunload的事件,但我不知道如何得到它的工作,如果它仍然是可用的。

Also, I've found an event called onbeforeunload, but I can't figure out how to get it working, if it still is available.

推荐答案

您需要确保的 ignore_user_abort()是尽快设置为true。如果有一个默认的设置它,那会更好。

You need to make sure the ignore_user_abort() is set to true as soon as possible. If there is a default setting for it, that would be better.

这篇关于通过阿贾克斯卸载运行PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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