Jquery:单击按钮刷新/重新加载页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19207781/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 23:26:21  来源:igfitidea点击:

Jquery : Refresh/Reload the page on clicking a button

javascriptjquery

提问by monda

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

我有一个在 ajax 调用后加载的按钮,点击后我想重新加载页面(就像我按 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.

但它做了一个简单的刷新,但我的页面没有发出新的请求来获取内容。它应该像我输入 URL 以获取该页面一样发生。

回答by Royi Namir

You should use the location.reload(true), which will release the cache for that specific page and force the page to load as a NEWpage.

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

The trueparameter forces the page to release it's cache.

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

回答by Lloyd Banks

If your button is loading from an AJAX call, you should use

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

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

instead of

代替

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

Also note the trueparameter for the location.reloadfunction.

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

回答by Anuj Aneja

Use document.location.reload(true)it will not load page from cache.

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

回答by Satpal

You can also use window.location.href=window.location.href;

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

回答by Satpal

Use this line simply inside your head with

在你的头脑中简单地使用这条线

       window.location.reload(true);

It will load your current page or view.

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

回答by abhit

use window.location.href = url

window.location.href = url