防止表单重新刷新 [英] Prevent form to repost on refresh
问题描述
给出是一个表格,其后是一个确认页面,在该页面中,您必须确认输入的是先前表格的数据.现在,如果用户刷新此概要页面,则先前表单中的数据将重新发布.有没有办法在JavaScript中防止这种情况发生?
Given is a form that is followed by a confirmation page where you have to confirm you entered data of previous form. Now if the user refreshes this recapitulation page, the data form the previous form reposts. Is there a way to prevent that in JavaScript?
我知道它不是理想的解决方案,它应该在服务器端发生.但是在这种情况下,我别无选择.
I know its not a ideal solution, it should happen on the server side. But i have no choice in this case.
推荐答案
您不能阻止用户使用javascript重新发布.此操作应在服务器端使用发布后重定向模式完成.
You can't prevent the user from reposting using javascript. This should be done server side using the redirect after post pattern.
一种可能但不可靠的解决方案是使用window.location.href
模拟来自javascript的重定向.
A possible but not robust solution is to simulate the redirect from javascript using window.location.href
.
这篇关于防止表单重新刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!