javascript Javascript重新加载()不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10748270/
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
Javascript reload() not working
提问by Peanut
I searched everywhere here to see since so many people ask this question, but no matter what, I keep getting undefined
..
我在这里到处搜索,因为有这么多人问这个问题,但无论如何,我不断得到undefined
..
function remove_item(itemid) {
var window = top.location;
var host = window.host;
$.ajax({
url: "http://"+host+"/backend/remove_lockbox.php?id="+itemid,
success: function() {
$(document).ajaxStop(function(){
window.top.location.reload();
});
}
});
}
That is my code. I tried window.location.reload
, host.location.reload
... I tried everything and I keep getting undefined
... The parent of location is always undefined
whether it's window
, host
, window.top
, ANYTHING.
Can someone PLEASE help me?
那是我的代码。我想window.location.reload
,host.location.reload
......我什么都试过,我不断收到undefined
...位置的父始终是undefined
它是否是window
,host
,window.top
,任何事情。有人可以帮帮我吗?
回答by epascarello
So you are doing
所以你在做
var window = top.location;
and than you do
比你做的
window.top.location.reload();
So you are actually saying
所以你实际上是在说
top.location.top.location.reload();
Why would you use a variable named window when that is already defined and has a different meaning? That is bad.
为什么要使用名为 window 的变量,因为它已经定义并具有不同的含义?那很不好。
If you are using frames I would expect to see something like
如果您正在使用框架,我希望看到类似
parent.location.reload(true);
or just a plain old window
或者只是一个普通的旧窗户
window.location.reload(true);
回答by Ishan Dhingra
try it this way, its working fine in chrome, as I know this should work fine in all modern browsers.
以这种方式尝试,它在 chrome 中工作正常,因为我知道这在所有现代浏览器中都可以正常工作。
function remove_item(itemid) {
var host = window.location.host;
$.ajax({
url: "http://"+host+"/backend/remove_lockbox.php?id="+itemid,
success: function() {
$(document).ajaxStop(function(){
window.location.reload();
});
}
});
}
Here is the working example of window.location
, window.location.host
and window.location.reload
.
这是window.location
,window.location.host
和的工作示例window.location.reload
。