forms - History.pushstate 和 HTTP POST 表单转发

标签 forms http-post page-refresh pushstate html5-history

我目前在 HTTP post 表单和历史推送状态方面遇到了一个小问题。

当我的用户在 example.com/page-1 中提交 POST 表单,然后单击此页面中的链接时,他们会被重定向到 example.com/page-2 带有history.pushstate。 JS 脚本只是更改当前的 url,将旧的内容推送到历史记录,然后显示新的内容。这对我来说非常有效。

问题:用户访问 example.com/page-2手动刷新页面(ctrl+r 或刷新按钮)时,Chrome 会提示用户再次提交表格;但该表单实际上位于 example.com/page-1 中,并且没有理由在这个"new"页面中再次询问。

有没有办法在 popstate 更改时清除 javascript 中所有先前提交的数据,以防止浏览器重新发布提示?或者我错过了我的历史状态的某些内容?或者浏览器目前还没有很好地实现它?

我只使用 Chrome 进行了测试,因为我没有使用其他浏览器实现 Pushstate。

最佳答案

也许可以尝试替换状态?请参阅this .

The replaceState() method

history.replaceState() operates exactly like history.pushState() except that replaceState() modifies the current history entry instead of creating a new one.

replaceState() is particularly useful when you want to update the state object or URL of the current history entry in response to some user action.

关于forms - History.pushstate 和 HTTP POST 表单转发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13649633/

相关文章:

amazon-web-services - AWS Cloudwatch 设置 WebHook

android - 多个 httpPost 到遥远的 Restful 服务 (JSON)

php - 不刷新php页面

javascript - 仅刷新/重新加载网页一次

testing - TestCafe重新加载页面并重新执行fixture hook

html - 创建没有后端的联系表?

php - 使用表单 'get' 方法删除添加到 url 的问号

c# - 如何以编程方式将 .NET 5 中的文件上传到 .NET 5 Rest API 而不会丢失内容?

jquery - 如果确认为 true,则调用另一个 jQuery 函数

java - 如何在具有动态下拉列表的Android中制作表单