php重定向头未通过ajax调用发送

php redirection headers not sent through ajax call

本文关键字:ajax 调用 重定向 php      更新时间:2023-09-26

我正在尝试从用ajax调用的php文件发送头。问题是,当我用php验证所有信息时,我想重定向到另一个页面,但标题不起作用!有什么想法吗?

代码的作用:

//------------- index.php
on click of input, function passes <input> values through $_POST to login.php
if($_SESSION[superman]==true){redirects to index_main.php}
//------------- login.php
all it does is validate forms and if login and password are correct, it sets $_SESSION [superman]=true

重定向只会重定向Ajax调用!如果您想更改浏览器中显示的页面,则需要在Ajax调用完成后使用Javascript重定向。

  • 让Ajax调用返回一个指示成功登录的值(例如字符串true,或者可能是要加载的页面的URL)
  • 检查Ajax调用的返回值。如果成功,请使用Javascript更改location.href