2010-09-30 118 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 
});