【发布时间】:2014-09-29 17:44:10
【问题描述】:
我有以下代码:
<?php
require_once 'assets/functions.php';
if(isset($_SESSION['userName'])){
header('Location:http://192.168.0.50/hub.php');
die();
}
$title = 'ResRes - Login';
printCSS($title);
?>
这是我的 index.php 文件的一部分。问题是加载后,window.location = result.location 或 header('Location:http://192.168.0.50/hub.php') 都不起作用。这变得非常令人沮丧。
我的javascript代码是:
function verifyUser(userEmail){
$.getJSON('verifyUser.php', {data : userEmail}
).done(function(result){
window.location.href = result.location;
alert(result.message);
console.log(result);
return false;
});
};
我怀疑 .done(function(result){...}) 甚至没有执行,因为没有 console.log() 发生,也没有警报本身。不知道为什么会有这种行为。
另外,为了确保在我的 verifyUser.php 文件中我有以下标题:
header('Content-Type: application/json');
在测试服务器和 wamp 服务器上不会发生这种情况。它被重定向。但是,在此生产服务器中,它不会重定向。用户必须手动刷新要发送到result.location 的页面或 index.php 上的标题所说的内容。
任何想法可能会发生什么?
编辑
在控制台上手动执行$.getJSON,输出如下:
$.get('verifyUser.php', {data : 'hector.admin@laestanciaschool.com'}).done(function(result) { console.log("Done called", result); });
Object {readyState: 1, getResponseHeader: function, getAllResponseHeaders: function, setRequestHeader: function, overrideMimeType: function…}
【问题讨论】:
-
您是否在控制台中收到 javascript 错误?尝试以 JSON(服务器端)返回 URL,然后在 javascript 中将窗口设置为该位置。
-
如果它在三分之二的服务器上工作,我猜你的代码不是问题。应该是服务器配置问题。检查您的 php.ini 文件,也许这 3 个 PHP 实例之间存在一些差异。如果我是正确的一些需要设置的选项。
标签: javascript php redirect