[英]php header redirect not working
我正在使用ajax調用來觸發使用標頭的php重定向。 根據chrome的開發人員工具,頁面的內容已加載(即:位於資源列表中),但是頁面從不重定向。
我沒有收到任何錯誤代碼。 這是PHP:
<?php
ini_set('display_errors', false);
if (!isset($_SESSION)) {
if($_POST['email']){
...several calls to external db...
if(strlen($response->supporter->item->Email))
//user is a member
header('Location: http://www.example.com/page-one/');
else
header('Location: http://another-site.com/');
}
}
?>
幾乎完全相同的代碼可在網站的另一部分使用。 有什么想法為什么要提取正確的內容,而不是將其加載到頁面上?
ajax調用是:
$.post("http://www.our_site.org/is_member.php", { email: email });
試試看:
<?php
ini_set('display_errors', false);
if (!isset($_SESSION)) {
if($_POST['email']){
...several calls to external db...
if(strlen($response->supporter->item->Email))
//user is a member
echo ('Location: http://www.example.com/page-one/');
else
echo ('Location: http://another-site.com/');
}
}
?>
在您的js內部執行以下操作:
$.ajax({
type: 'POST',
url: "http://www.our_site.org/is_member.php",
data: {email: email },
success: function(output){ window.location = output; }
dataType: dataType
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.