如何使用JavaScript刷新页面?
当前回答
我想有很多方法会奏效:
window.location.reload();history.go(0);window.location.href=window.location.html;
其他回答
可能最短(12个字符)-使用历史
history.go()
要使用jQuery重新加载页面,请执行以下操作:
$.ajax({
url: "",
context: document.body,
success: function(s,x){
$(this).html(s);
}
});
这里我使用的方法是Ajax jQuery。我在Chrome 13上测试了它。然后我将代码放入将触发重载的处理程序中。URL为“”,表示此页面。
编辑:不幸的是,我必须很快记下这个答案,因为问题已经改变,用户似乎不太清楚他们在问什么。一些用户评论说,刷新与重新加载页面不同;查看此问题的修订[https://stackoverflow.com/posts/5404839/revisions]据我所知,最初的问题是用AJAX刷新页面,这是ASYNCHRONOUS。。。,刷新页面应该意味着向页面获取新的和更新的内容。无论如何,这个答案很快就会消失/
问题应该是,
如何使用JavaScript刷新页面
window.location.href = window.location.href; //This is a possibility
window.location.reload(); //Another possiblity
history.go(0); //And another
你被宠坏了。
有很多方法可以重新加载当前页面,但使用这些方法,您可以看到页面更新,但不会有很少的缓存值,因此要克服这个问题,或者如果您希望发出硬请求,请使用以下代码。
location.reload(true);
//Here, it will make a hard request or reload the current page and clear the cache as well.
location.reload(false); OR location.reload();
//It can be reload the page with cache
这对我有用。
function reload(){
location.reload(true);
}