提交后重置表单并清除缓存
大多数浏览器都会缓存表单值,因此当用户导航到另一个页面然后按下后退按钮时不必重新开始。
使用 jquery 表单插件,在表单成功提交后也会发生这种情况。
以下场景:
用户提交表单
显示消息提交成功,表单已清除
用户导航到其他页面
用户按下后退按钮
页面恢复到提交表单之前的状态。
>
提交后调用resetForm()只会返回初始表单值,但不能解决缓存问题。
$(document).ready(function(){
$('form').ajaxForm({
success: function(responseText, statusText){
displayMessage('form successful');
$('form').resetForm();
}
});
});
加载页面时调用 resetForm() 可以解决缓存问题,但会在页面之间导航时破坏预期的浏览器行为:
$(document).ready(function(){
$('form').ajaxForm().resetForm();
});
是否有办法在成功提交后清除缓存?
Most browsers cache form values, so when the user navigates to another page and then presses the back button doesn't have to start over again.
With the jquery form plugin this also happens after the form has been submitted successfully.
The following scenario:
user submits form
message is shown that submission was successful and form is cleared
user navigates to some other page
user presses the back button
page is restored to the state before the form was submitted.
Calling resetForm() after submit only brings back the initial form values but doesn't solve the cache issue.
$(document).ready(function(){
$('form').ajaxForm({
success: function(responseText, statusText){
displayMessage('form successful');
$('form').resetForm();
}
});
});
Calling resetForm() when the page is loaded solves the cache issue but breaks the expected browser behavior when navigating between pages:
$(document).ready(function(){
$('form').ajaxForm().resetForm();
});
Is there a way to clear the cache after a successful submit?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不太喜欢 JQuery,但通常可以使用
源代码来关闭表单值的存储,例如 here据
我所知,没有其他跨浏览器的方式可以影响浏览器在缓存中存储的值。我认为不太可能以编程方式访问这些东西,因为这会带来复杂的安全隐患。
I'm not that much into JQuery but the storing of form values can be generally switched off using
source for example here
As far as I know, there is no other cross-browser way of influencing what values the browser stores in its cache. I think it is unlikely to get access to this stuff programmatically because of the complex security implications this would bring along.