Javascript jQuery - 在 ajax 调用后重定向
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3084692/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery - redirect after ajax call
提问by Ian morgan
I have the following code, however im having a problem getting window.location to work
我有以下代码,但是我在让 window.location 工作时遇到问题
$('.test_container a').click(function() {
$.ajax({
url: $(link).attr('href'),
type: 'GET',
dataType: 'json',
beforeSend: function() {
$('#lightbox').show();
},
success: function(data) {
$('#lightbox').hide();
window.location(data);
}
});
return false;
});
If window.location.replace is used instead it does work, however this then doesnt allow the brwser back buttons to work.
如果使用 window.location.replace 代替它确实可以工作,但是这不允许 brwser 后退按钮工作。
Does anyone know of any solution?
有谁知道任何解决方案?
Thanks
谢谢
回答by Sarfraz
Instead of:
代替:
window.location(data);
Use:
用:
window.location = data;
The locationis a propertyof the windowobject not a method.
的location是一个属性的的window对象不是一个方法。
回答by Smith
for some reason, i tried
出于某种原因,我试过
window.location = data;
without success, but when used
没有成功,但使用时
document.location.href = data;
it worked, you can consider this too
它有效,你也可以考虑这个

