让页面告诉浏览器不缓存/ preserve输入值 [英] Make page to tell browser not to cache/preserve input values

查看:107
本文介绍了让页面告诉浏览器不缓存/ preserve输入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大多数浏览器缓存的形式输入值。因此,当用户刷新页面,输入具有相同的值。

Most browser cache form input values. So when user refreshes page, the inputs have same values.

下面是我的问题。当用户点击保存,服务器验证发布的数据(例如,选中的产品),并且如果无效,并将其发送回浏览器。然而,如上所述,即使服务器清除选择一些值,它们仍然可以因为浏览器的缓存中选择!我的数据有无形的(直到父项选择)复选框,因此用户可能根本不知道有些previous值仍处于选中状态,直到再次点击保存,并得到错误信息 - 即使用户认为它不是。这是刺激性的。

Here's my problem. When user clicks Save, server validates POSTed data (e.g. checked products), and if not valid, sends it back to browser. However, as stated above, even if server clears selection for some values, they may still be selected because of browser cache! My data has invisible (until parent item selected) checkboxes, so user may be even not aware that some previous value is still selected, until clicks Save again and gets error message - even though user thinks it's not. Which is irritating.

这可以通过执行按Ctrl-F5解决,但它甚至不是一个解决方案。是否有自动/程序化的方法来告诉浏览器不缓存某种形式/页的表单输入数据?

This can be resolved by doing Ctrl-F5, but it's not even a solution. Is there an automatic/programmatic way to tell browser not to cache form input data on some form/page?

推荐答案

您明确设置的值作为空白?例如:

Are you explicitly setting the values as blank? For example:

<input type="text" name="textfield" value="">

这应该停止把浏览器的数据在它不应该。另外,您也可以在自动完成属性添加到表单标签:

That should stop browsers putting data in where it shouldn't. Alternatively, you can add the autocomplete attribute to the form tag:

<form autocomplete="off" ...></form>

这篇关于让页面告诉浏览器不缓存/ preserve输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆