![](/img/trans.png)
[英]In PHP header('Location: /facemash'); is not refreshing the Page?
[英]Refreshing a page with javascript using php header('location')
我想使用一个php文件来处理我的所有投票请求。
目前,如果未设置siteType
,脚本将转发用户并显示消息。 如果用户有JS
,那么它将返回一个json对象和ajax页面。
if(!isset($_COOKIE['siteType'])){
displayMessages('bad', 'Before you can continue you must select which category you would like to be in.');
header('Location:/');
exit;
}
我需要它,因为如果执行上面的PHP代码页面将重新加载,我假设使用JavaScript并阅读http标头?
[编辑]我没有说清楚,但这是一个ajax请求。 我不输出任何HTML。 所以这真的只是让js处理标题?
您无法使用php标头刷新页面('location')因为,标题('Location:xxx'); 必须是你的PHP脚本的唯一输出,它是一个标题,你不能把它放在javascript语法之后
PHP
echo '<meta http-equiv="refresh" content="0">';
使用Javascript
window.location.reload();
也许这对你来说是一些解决方案,
if(!isset($_COOKIE['siteType'])){
displayMessages('bad', 'Before you can continue you must select which category you would like to be in.');
echo '<script>window.location.reload()</script>';
exit;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.