Take the 2-minute tour ×

I'm wondering if I can use the header("Location: someFile.php"); from a script that is called via AJAX. When I am calling this script the response is the page I am attempting to redirect to.

If not, what are some options to handle redirecting users via an ajax call?

I've tried window.location() but it does not capture browser history (can't use the back button).

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

No, if you issue header("Location: ...") - you will redirect an AJAX call itself, but not the user's browser window. The only way is to window.location.href="http://my.new.location/xxx/yyyy"

And the "back button problem" is common for a whole AJAX thing.

Hovewer, setting a window.location.href from a pure javascript (not AJAX) makes browser 'back' button work as expected. You could try with AJAX.

share|improve this answer
add comment

Your Answer


