views:

49

answers:

1

Hi all,
I'm using an ajax call to trigger a php redirect using headers. According to chrome's developer tools the content of the page is loaded (ie: is in the resource list), but the page never redirects.

I'm not getting any error codes. Here's the 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/');
  }
}
?>

Nearly exactly the same code works in another part of the site. Any ideas why this is pulling the correct content, but not loading it on the page?

the ajax call is:

$.post("http://www.our_site.org/is_member.php", { email: email });
A: 

Try That:

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

?>

And inside of your js do that:

$.ajax({
  type: 'POST',
  url: "http://www.our_site.org/is_member.php",
  data: {email: email },
  success: function(output){ window.location = output; }
  dataType: dataType
});
ITroubs