【问题标题】:Redirection through json_encode in php通过php中的json_encode重定向
【发布时间】:2017-03-10 18:10:45
【问题描述】:
if ($this->register($email, $register_status))
                    {
                        $this->sendConfirmationEmail($email);
                        echo json_encode(array("message" => $this->error = $this->l('Your email was registered. Thank You!'),"code" => 1));
                        die();
                    }

这是我的代码,我想在执行此代码后重定向页面

【问题讨论】:

  • die()函数之前使用header("Location: your_page.php");!!问题在哪里
  • 它显示错误 XMLHttpRequest 无法加载 (abc.)。请求的资源上不存在“Access-Control-Allow-Origin”标头。因此不允许访问 Origin ('dev1.abc.')。
  • 查看这篇文章可能会有所帮助http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource

标签: php json redirect


【解决方案1】:

只需使用 header("Location: your_page.php");在死之前();

if ($this->register($email, $register_status))
     {
$this->sendConfirmationEmail($email);
echo json_encode(array("message" => $this->error = $this->l('Your email was registered. Thank You!'),"code" => 1));
header("Location: your_page.php");
die();
                        }

如果错误

添加第一行首页

    <?php 
ob_start();
    if ($this->register($email, $register_status))
         {
    $this->sendConfirmationEmail($email);
    echo json_encode(array("message" => $this->error = $this->l('Your email was registered. Thank You!'),"code" => 1));
    header("Location: your_page.php");
    die();
                            }?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-21
    • 1970-01-01
    • 1970-01-01
    • 2013-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-20
    相关资源
    最近更新 更多