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

编程入门 行业动态 更新时间:2024-10-25 08:24:46
本文介绍了从 ajax 加载的子页面重新加载页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用 ajax 将 php 生成的内容加载到某些菜单单击的主 div 中.

I am using ajax to load php generated content into main div on some menu click.

我想要做的是具有某种重新加载功能 - 如果某些超时到期,我希望用户重新进行身份验证,我会在将内容加载到 div 之前通过单击菜单检查此功能.

What I would like to do is have some kind of reload functionality - if some timeout expires I want user to reauthenticate, I am checking this on menu click before the content is loaded into div.

如果我用 php 来做这件事标头(位置:登录");

If I do this with php's header("location:login");

我想它想在加载 div 内重定向,但我希望整个页面都重定向...

I guess it wants to redirect inside loading div, but I want the whole page to redirect...

推荐答案

你能做的最好的事情就是这样

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 = "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

更多推荐

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

本文发布于:2023-11-01 19:57:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550261.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加载   页面   ajax

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!