且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从 ajax 加载的子页面重新加载页面

更新时间:2023-11-10 23:52:04

你能做的***的事情就是这样

The best you can do is some thing like this

在文件顶部

ob_start();

将其添加到 php 文件的末尾

Add this to the end of your php file

if($_SEESION['active']){
    ob_end_flush()
}else{
    ob_clean();
    echo "{Session_invalid}";
    ob_end_flush();
}

然后在你的 AJAX(XMLHttpRequest)

Then in your AJAX(XMLHttpRequest)

ajax = new XMLHttpRequest();
ajax.open("GET", "/folder/yourFile.php", true);
ajax.onreadystatechange = function(){
    if(readyState == 4){
        if(ajax.responseText == "{Session_invalid}"){
            document.location = "http://your.authenticate.url/"
        }else{
            mydiv.innerHTML = ajax.responceText
        }
    }
}
ajax.send();

请注意,我是根据您所说的构建此内容的,不要删除您的 ajax,只需将 if 检查添加到 AJAX 中

Please note i have built this on what you have said dont remove your ajax just add the if check into the AJAX

此外,此代码已构建,因此您可以将其添加到任何文件中,即使您没有制作 php 文件,因此它只是顶部和底部的编辑,但请确保在标签中

Allso this code has been built so you can add it into any file, even if you did not make the php file so its just top and bottom edits please make sure there in the tags though

这匹配user228395 点 1

This matches user228395 point 1