开发者

Is it possible to use the php header() command from an ajax call to redirect?

开发者 https://www.devze.com 2023-01-03 09:55 出处:网络
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 redir

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号