PHP头重定向消息发送到浏览器,但不重定向

  • 本文关键字:重定向 浏览器 消息 PHP php
  • 更新时间 :
  • 英文 :


我的代码的相关部分如下所示。

try
{
  $customer = StripeCustomer::create(array(
    'email' => $_POST['custEmail'],
    'source'  => $_POST['stripeToken'],
    'plan' => 'my_plan'
  ));
 header("Location:https://something.com"); 
  exit;
}
catch(Exception $e)
{
  //header('Location:oops.html');
    echo "no work";
  error_log("unable to sign up customer:" . $_POST['custEmail'].
    ", error:" . $e->getMessage());
}

来自我的PHP文件的响应包括:

HTTP/1.1 302 Found
Date: Sun, 31 Jul 2016 21:13:52 GMT
Server: Apache/2.4.23 (Amazon) OpenSSL/1.0.1k-fips PHP/5.6.22
X-Powered-By: PHP/5.6.22
Location: https://something.com
Content-Length: 0
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8

所以,消息回来了(我想),但我的浏览器没有重定向。我错过了什么?

对PHP的请求是Ajax…响应数据是我试图重定向到的页面的完整HTML代码。

位置标头的意思是"您要查找的资源在这里"。这并不意味着"在主浏览器窗口中显示此URL处的资源"。浏览器视口不会重定向,无论处理请求的是什么,都会重定向。

浏览器将遵循重定向,响应将传递给Ajax回调函数(除非它触发了诸如违反同源策略之类的错误)。

如果您想在浏览器中加载页面,那么就不要使用Ajax。提交一个常规表单。Ajax的全部目的是避免在主视图中加载新文档。

最新更新