会话 cookie 和 HTML 表单
我有一个 HTML 页面,其中包含一个表单,其中包含:文本、复选框和下拉菜单。
完成后,用户单击提交并进入一个新页面,在此页面上我有一个 JavaScript,它对输入执行一些分析,然后写入其结果。
问题:将表单输入传输到下一页,我需要能够访问下一页上的表单输入,
例如,如果文本输入为“true”,我可以在下一页上访问它并将其分配给变量。
所以目前我认为最好的方法是使用会话 cookie。
然而,我正在努力研究将所有表单输入存储到 cookie 中的代码,以及如何在第二页上访问它们。
任何帮助将不胜感激!或任何其他方法来完成此任务的想法!
谢谢!
I have a HTML page containing a form which consists of; text, check boxes and drop-down menus.
on completion the user clicks submit and is taken to a new page, on this page I have a JavaScript which performs some analysis on the inputs and then writes its results.
THE PROBLEM: transferring the form inputs to the next page, I need to be able to access the form inputs on the next page,
e.g if text input was "true" I can access this on the next page and assign it into a variable.
So at the moment I'm thinking the best way to do this is with a session cookie.
However I'm struggling with the code for storing all the form inputs into the cookie and then how to access them on the second page.
Any help would be greatly appreciated! or any ideas on other methods to complete this task!
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您不需要在服务器端执行任何操作,则可以使用
method='GET'
而不是POST
提交表单。这样,输入将在 url 中可用,并且可以在 JavaScript 中进行解析。例如:
If you don't need to do anything server-side, you can submit the form using the
method='GET'
rather thanPOST
. That way, the inputs will be available in the url and can be parsed in your JavaScript.For example:
谷歌很快就想出了这个 http://www.fijiwebdesign.com/blog/remembering-form-input-data-with-javascript-and-cookies-before-submission.html
它应该很好地说明如何做到这一点
A quick google came up with this http://www.fijiwebdesign.com/blog/remembering-form-input-data-with-javascript-and-cookies-before-submission.html
It should give a good idea of how to do it
您可以在序列化对象 (JSON) 内或使用 urlencoded 字符串(如 var1=test&var2=true)对数据进行编码。将此字符串存储到 cookie 中,您可以在下一页中使用它。
You can encode your Data inside an serialized Object (JSON) or using urlencoded strings (like var1=test&var2=true). Store this string into a cookie and you can use it on the next page.