如何在Javascript中没有POSTDATA警告的情况下重新加载页面? [英] How do I reload a page without a POSTDATA warning in Javascript?

查看:170
本文介绍了如何在Javascript中没有POSTDATA警告的情况下重新加载页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用以下方法重新加载页面:

I want to reload a page using:

window.location.reload(true); 

但我收到POSTDATA警告,因为刷新功能想要重新发送以前的POST表单数据。如何在没有此警告的情况下刷新页面?

But I receive the POSTDATA warning because the refresh function want to resend previous POST form data. How can I refresh my page without this warning?

更新:我无法控制项目!我无法解决POST本身问题!

UPDATED: I have no control of the project! I can't workaround the POST itself!

推荐答案

只需更改 window.location 在JavaScript中危险,因为用户仍然可以点击后退按钮并重新提交帖子,这可能会产生意外结果(例如重复购买)。 PRG是一个更好的解决方案

Just changing window.location in JavaScript is dangerous because the user could still hit the back button and resubmit the post, which could have unexpected results (such as a duplicate purchase). PRG is a much better solution

使用发布/重定向/获取(PRG)模式


为避免此问题,许多Web应用程序使用PRG模式 - POST操作不是直接返回HTML页面,而是返回重定向命令(使用HTTP 303响应代码(有时是302)和HTTPLocation响应头),指示浏览器使用HTTP GET请求加载不同的页面。然后可以安全地将结果页面加入书签或重新加载而不会出现意外的副作用。

To avoid this problem, many web applications use the PRG pattern — instead of returning an HTML page directly, the POST operation returns a redirection command (using the HTTP 303 response code (sometimes 302) together with the HTTP "Location" response header), instructing the browser to load a different page using an HTTP GET request. The result page can then safely be bookmarked or reloaded without unexpected side effects.

这篇关于如何在Javascript中没有POSTDATA警告的情况下重新加载页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆