即使提交基于PRG的表单,Chrome浏览器也会追踪2条历史logging
当提交实现“发布+相同页面redirect+获取”方法的表单时,Chrome跟踪两个历史logging条目 – 而不仅仅是一个 – 。
演示这个奇怪的行为的步骤。
1 – 我浏览到表单页面裸页面:demo.html。 裸页面:
2 – 我填写表格。 填写表单:
3 – 我提交表格。 Submited – 这是空的forms(在demo.html,redirect从我的基于PRG的redirect到相同的page.php):
4 – 我点击浏览器的“返回”button一次。
Chrome跳回填充表格(步骤)
5 – 我需要再次点击浏览器的“返回”button才能到达我浏览页面之前(例如我的浏览器的“谷歌”默认页面):
Chrome(版本25.0.1364.172)和Safari(6.0.2)
我在期待什么
我期望有一个单一的浏览器的“返回”点击到达窗体之前的页面。 实际上,Firefox(19.0.2)Opera(12.11)和IE(从版本6到最新的10)是如何运行的。
我的源代码
demo.html
<!DOCTYPE html> <html lang="en"> <head> </head> <body> <form action="redirect-to-same-page.php" method="post"> Type something and submit: <input type="text" name="something" /> <!-- optional: autocomplete="off" --> <input type="submit" value="submit" /> </form> </body> </html>
redirect到同page.php文件
<?php header('Location: demo.html', true, 302); // not any of true/false 302/303 combinations are working // not working either: header("Refresh: 0; demo.html"); exit; ?>
什么Chrome的网站督察揭示…
1提交之前:
2提交后:
我的问题
我读了类似的问题和潜在的答案,但是他们都没有解决我的问题。
此行为是Chrome / Safari问题还是function*? (*在提交失败的情况下,它会保留您的填写表格的完整备份)
是否有一个正确的或更多的防守code.js或PHP来避免这种行为?
谢谢你的帮助