Semur Nabiev
Semur Nabiev

Reputation: 800

php redirection headers not sent through ajax call

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?

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

Upvotes: 3

Views: 1324

Answers (1)

Emil Vikstr&#246;m
Emil Vikstr&#246;m

Reputation: 91983

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.

Upvotes: 5

Related Questions