如何在没有浏览器询问我是否要重新发送的情况下刷新网页 [英] How can I refresh a webpage without the browser asking if I want to resend again
问题描述
我有以下代码来刷新我的网页。如果我不通过POST提交任何内容,它会很有用,但是如果我这样做,当我的网页刷新时,我会从浏览器收到一条消息(见下图)
I got the following code to refresh my webpage. It works great if I don't submit anything with POST but if i do, i get a message from the browser when my webpage refreshes (see image below)
location.reload(true);
我不是在寻找浏览器设置调整。我正在寻找替代代码来刷新而不问。
I'm not looking for the browser settings tweak. I'm looking for alternative code to refresh without asking.
推荐答案
这是由于 POST
而不是 GET
所请求的页面造成的。刷新将重新提交 POST
数据。你可以使用强制获取get.location = window.location.href;
。
This is caused due to the page being requested by POST
instead of GET
. Refreshing will resubmit the POST
data. You can force a get using window.location = window.location.href;
.
如果你想允许人们通过浏览器控件重新加载页面然后你需要实现 PRG模式,重定向到在 POST
之后获取
。
If you want to allow people to reload the page through their browser controls then you will need to implement the PRG pattern which redirects to a GET
after a POST
.
这篇关于如何在没有浏览器询问我是否要重新发送的情况下刷新网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!