2010-09-30 121 views
0


我正在使用ajax調用來觸發使用頭的php重定向。根據chrome的開發者工具,頁面的內容被加載(即:在資源列表中),但頁面不會重定向。php頭重定向不工作

我沒有收到任何錯誤代碼。這裏的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 }); 
+0

請出示Ajax調用 – 2010-09-30 15:51:55

+8

等一下,你是不是使用Ajax獲取它並期望標題(「位置」)影響父頁面?因爲那永遠不會起作用。 – 2010-09-30 15:52:52

+0

啊哈!是的,那麼我將如何完成我想要做的事情? – danwoods 2010-09-30 15:54:40

回答

0

嘗試:

<?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 
});