如何刷新网页而不让浏览器询问我是否要再次重新发送

发布于 2024-11-19 17:25:59 字数 232 浏览 0 评论 0原文

我得到以下代码来刷新我的网页。如果我不使用 POST 提交任何内容,它会很好用,但如果我这样做,当我的网页刷新时,我会从浏览器收到一条消息(见下图),

location.reload(true);

我不是在寻找浏览器设置调整。我正在寻找替代代码来刷新而无需询问。 在此处输入图像描述

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.
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

情话难免假 2024-11-26 17:25:59

这是由于页面是通过 POST 而不是 GET 请求的。刷新将重新提交POST数据。您可以使用 window.location = window.location.href; 强制获取。

如果您希望允许人们通过浏览器控件重新加载页面,那么您需要实现 PRG 模式POST 之后重定向到 GET

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;.

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.

燕归巢 2024-11-26 17:25:59

这将请求页面而不是重新加载。

window.location = window.location;

This will request for a page and not a reload.

window.location = window.location;
作业与我同在 2024-11-26 17:25:59

GET 与 POST

解决方案:不要 POST。 GET 应该是幂等的(取决于环境变化),POST 应该是一种修改。

POST 之后,您应该立即执行 GET 以使用 POST 结果重新加载页面。然后就可以随意刷新了。

示例:

page_1.html

<form method="POST" action="go.php"> ... </form>

go.php:

<?php
    // do stuff...
    header('Location: http://www.foo.com/page2.html');
?>

page2.html:

<script type="text/javascript"> location .reload (true); </script>

GET vs. POST

The solution: don't POST. GET is supposed to be idempotent (up to environmental changes), POST is supposed to be a modification.

After the POST, you should be performing an immediate GET to reload the page with the result of the POST. Then you can refresh at will.

Example:

page_1.html

<form method="POST" action="go.php"> ... </form>

go.php:

<?php
    // do stuff...
    header('Location: http://www.foo.com/page2.html');
?>

page2.html:

<script type="text/javascript"> location .reload (true); </script>
做个ˇ局外人 2024-11-26 17:25:59

这是由浏览器端控制的,而不是由您控制的(即您无法控制它)。如果您想向用户显示一个无需重新发布选项即可刷新的页面,则必须通过在发布后重定向到使用 GET 而不是 POST 检索的页面来完成此操作。

尝试 JavaScript 重定向。或者,使用 AJAX 发布信息,这意味着刷新会重新加载原始页面,而不是 ajax 发布的结果。

This is controlled on the browser end and not yours (ie you CAN'T control it). If you want to show the user a page that can be refreshed without the repost option, you'll have to do it via a redirect following the post to a page that you retrieve with a GET not a POST.

Try a javascript redirect. Or alternatively, POST the information using AJAX which will mean refresh reloads the original page, not the results of your ajax post.

南笙 2024-11-26 17:25:59

您可以将数据保存到 window.name 并使用 window.location = window.location.href 技巧。当 onload 时,检查 window.name 中是否有数据,将其取回并从那里删除它。在这种情况下,我经常使用 window.name 作为“会话”存储。

you can save your data to window.name and use the window.location = window.location.href trick. and when onload, check if you have data in window.name, get it back and remove it from there. i use the window.name as "session" storage quite often for situations like this.

番薯 2024-11-26 17:25:59

(我会说西班牙语,我会尽力而为)
就我而言,我有一个按钮可以在数据库中查找未处理的票证,因此,每次我想知道是否有新的票证时,我都需要按该按钮,我用下一个 javascript 函数解决了这个问题,

<script type="text/javascript" language="javascript">  
    setTimeout('document.getElementById("btn_busca_ticket").click()', 10000);
</script>

其中 10000 是之间的时间每次刷新(10秒)

如果你没有按钮,你可以创建一个带有ID和提交的隐藏按钮
(它不是那么优雅,但对我有用)

(I'm spanish speaker, I´ll do my best)
In my case, I have a button to looking for open tickets in a DB, so, i need to press that button every time that I wanna know if there are new ones, I resolved with the next javascript function

<script type="text/javascript" language="javascript">  
    setTimeout('document.getElementById("btn_busca_ticket").click()', 10000);
</script>

where 10000 is the time between every refresh, (10 seconds)

if you don't have a button, you can create a hidden one with an ID and a submit
(it's not so elegant, but works for me)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文