PHP重定向头不通过Ajax调用发送不通过、重定向、PHP、Ajax

2023-09-10 17:55:29 作者:动了情的痞子

我想从那个叫阿贾克斯一个PHP文件发送头。问题是,当我验证所有的信息,使用PHP,我想重定向到另一个页面,但头不工作!任何想法?

什么是code的作用:

  // -------------的index.php
在点击输入,函数将与LT;输入>通过$ _ POST值的login.php
如果($ _ SESSION [超人] ==真){重定向到index_main.php}

// -------------的login.php
它所做的就是验证表单,如果登录名和密码是正确的,它设置$ _SESSION [超人] =真
 

解决方案

重定向只会重定向的 Ajax调用的!如果你想改变显示的页面在浏览器中,你需要使用Javascript一次Ajax调用完成重定向。

请您的AJAX调用返回一个值,指示登录成功(例如字符串或者URL来要加载的页面) 检查Ajax调用的返回值。如果成功,使用Javascript变化 location.href

i am trying to send header from a php file that is called with ajax. problem is, when i validate all information with php, i want to redirect to another page but headers dont work! any ideas?

AJAX

what the code does:

//------------- 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

解决方案

The redirect will only redirect the Ajax call! If you want to change the displayed page in the browser, you'll need to redirect using Javascript once the Ajax call completes.

Make your Ajax call return a value indicating successful login (for example the string true or maybe the URL to the page you want to load) Check the return value of the Ajax call. If success, change location.href using Javascript.