如何解决在浏览器上按回后,如何使用pushstate / reloadstate保留/填充表单值?
我有一个验证机制((冗余)验证表单输入):
if (valid) {
form.attr("data-valid","true");
form.find("input[type='submit']").attr("disabled","disabled");
var form = $(this);
console.log(form[0]);
/// store data here since it would be valid
// for (var i = 0; i<this.length; i++ ) {
// localStorage.setItem(this[i].name,this[i].value);
// console.log(localStorage);
// // localStorage.clear();
// }
// history.pushState(data,event.target.textContent,event.target.href);
// return event.preventDefault();
console.log(this)
let serializedForm = $(this).serializeArray();
let href = window.location.href;
//window.location.hash = 'coming';
window.history.pushState(serializedForm,"",href);
} else {
event.preventDefault();
event.stopPropagation();
}
return valid;
如果表单有效,我想保存表单状态(表单的值保持不变)。
这是我要介绍的情况:用户具有“有效”表单输入,保存表单状态,并且由于表单有效,因此提交按钮会将他带到下一页,这是错误的,因为用户已经存在。用户按下浏览器上的“后退”按钮,就可以看到他刚提交的表单值(尽管有效)。
我当时正在考虑使用cookie或localStorage,但这似乎是一种“更简单,更有效的方法”
请紧记,因为输入在“ if”块中的最后一段代码之后“有效”,他被重定向到下一页(这将提示显示该用户已经存在的错误消息)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。