Is it possible to use the php header() command from an ajax call to redirect?
I'm wondering if I can use the header("Location: someFile.php"); from a script that is called via AJAX. When I am ca开发者_开发百科lling 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).
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.
精彩评论