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.
我想知道我是否可以使用标题(“Location:someFile.php”);来自通过AJAX调用的脚本。当我调用此脚本时,响应是我尝试重定向到的页面。
If not, what are some options to handle redirecting users via an ajax call?
如果没有,有哪些选项可以通过ajax调用来重定向用户?
I've tried window.location() but it does not capture browser history (can't use the back button).
我已经尝试过window.location()但它没有捕获浏览器历史记录(不能使用后退按钮)。
1 个解决方案
#1
5
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"
不,如果您发出标题(“位置:...”) - 您将重定向AJAX调用本身,而不是用户的浏览器窗口。唯一的方法是window.location.href =“http://my.new.location/xxx/yyyy”
And the "back button problem" is common for a whole AJAX thing.
而“后退按钮问题”对于整个AJAX来说很常见。
Hovewer, setting a window.location.href from a pure javascript (not AJAX) makes browser 'back' button work as expected. You could try with AJAX.
Hovewer,从纯javascript(而不是AJAX)设置window.location.href使浏览器“后退”按钮按预期工作。你可以试试AJAX。
#1
5
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"
不,如果您发出标题(“位置:...”) - 您将重定向AJAX调用本身,而不是用户的浏览器窗口。唯一的方法是window.location.href =“http://my.new.location/xxx/yyyy”
And the "back button problem" is common for a whole AJAX thing.
而“后退按钮问题”对于整个AJAX来说很常见。
Hovewer, setting a window.location.href from a pure javascript (not AJAX) makes browser 'back' button work as expected. You could try with AJAX.
Hovewer,从纯javascript(而不是AJAX)设置window.location.href使浏览器“后退”按钮按预期工作。你可以试试AJAX。