node.js - Node js / Express js form do not expire after posting data
问题描述
First and foremost I would like to inform you that I am new to node js!
I have been asked to implement a simple application in node js. So, I have created a form that submits via POST method its data. When data are retrieved and processed I render another page in order to display some info regarding the submitted data and the results of the whole process.
My problem is that users are able to click the back button from the browser, load the submitted data again and re-press the submit button.
It sounds stupid but I'am stuck in here for days...
Thanks in advance.
解决方案
这是由于各种浏览器的HTTP 缓存策略:FireFox 中的“后向缓存”(BFCache);Safari等中的“页面缓存”。它是为了优化导航速度而实现的。本质上,它缓存了整个页面的 DOM,包括非 HTTPS 站点的表单元素。可以通过侦听加载页面的事件或通过使用来自服务器的HTTP 标头不缓存该页面(例如Cache-Control: no-cache, max-age=0, must-revalidate, no-store
)来以编程方式清除表单元素。
要Cache-Control
在 Express 中设置响应的标头,请使用set
响应对象的方法:
res.set('Cache-Control', 'no-cache, max-age=0, must-revalidate, no-store');
推荐阅读
- google-image-search - google-picker 图片搜索 403,很抱歉,您无权访问此页面
- kubernetes - Kubernetes 中用于翻译 LAN 主机的 DNS 服务器
- javascript - 在 HTML 表格中,当用户单击搜索字段上的关闭按钮时,如何显示列中的所有值?
- django - Django BooleanField(default=False) 混淆
- javascript - 仅使用 Next.js 预渲染首页
- r - R:下标超出范围
- python - 在跨账户 s3 存储桶之间复制文件时重命名文件
- vue.js - 在 v-data-table 标题中实现一个复选框
- c++ - 即使在 setprecision 之后,“Double”也不会打印超过 6 个有效数字
- python - 即使行在数据库中,Python mySQL.connector 也会返回 None