45

I have a button which loads after a ajax call , on clicking i want to reload the page (like i press f5)

I tried

$( ".delegate_update_success" ).click(function() {
    location.reload();
});

but it does a simple refresh, but my page does not makes a new request to get the contents. It should happen just like I am entering URL to get that page.

4

7 回答 7

105

您应该使用location.reload(true),它将释放该特定页面的缓存并强制该页面作为页面加载。

true参数强制页面释放它的缓存。

于 2013-10-06T10:28:44.417 回答
10

如果您的按钮是从 AJAX 调用加载的,您应该使用

$(document).on("click", ".delegate_update_success", function(){
    location.reload(true);
});

代替

$( ".delegate_update_success" ).click(function() {
    location.reload();
});

还要注意函数的true参数location.reload

于 2013-10-06T10:48:24.767 回答
8

使用document.location.reload(true)它不会从缓存加载页面。

于 2013-10-06T10:31:07.840 回答
6

你也可以使用window.location.href=window.location.href;

于 2013-10-06T10:40:42.307 回答
4

在你的脑海中使用这条线

       window.location.reload(true);

它将加载您当前的页面或视图。

于 2014-03-10T09:39:00.577 回答
-1

简单的方法可以是 -

只是href="javascript:location.reload(true);

你的答案是

location.reload(true);

谢谢

于 2020-10-24T06:13:33.700 回答
-1

利用window.location.href = url

于 2016-08-30T13:35:31.357 回答