如何保存HTML页面的输入值? [英] How to save the input values of an HTML page?

查看:1396
本文介绍了如何保存HTML页面的输入值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,这个要求可能看起来很奇怪。但我想知道如何实现这一目标?

我有一个HTML文件,它有几个输入框,复选框,单选按钮等。我想保留一个用户[实际上我]在这个页面上执行。就像用户勾选了一个复选框,然后下一次打开该文件的任何人都应该看到该复选框为勾选。

使用HTTP cookies可以轻松完成这件事。但是我不想使用cookies。

答案可以简单到不,你不能这样做:)



编辑

这是没有正确说明问题的问题。



我想我不能使用数据库,就好像我将HTML页面发送给某人然后他/她将无法看到我的更改。我希望我的更改也反映在其他系统上。 [多数民众赞成在我没有去cookies的原因]。其他解决方案,我在想,是使用FileSystemObject。其他解决方案?答案可以是你不能这样做:D

解决方案

将表单元素的更改事件添加到AJAX提交中,将提交日志记录到数据库中,然后在任何页面上从数据库中获取最新状态以进行呈现。



编辑

如果您希望这些更改对其他用户同时显示,那么您可以使用jQuery轮询来更新页面 - 让页面定期轮询服务器以获取最新状态。



话虽如此,如果你给他们一个服务器链接而不是实际的文件,他们将会看到你的数据库变化。



然而,这听起来像你想要真正发送文件(而不是将某人发送到Web服务器),在这种情况下,你可以采取以下其中一种方法:




  • 您的PHP /任何文件(甚至可以通过javascript执行此操作)输出一个HTML文件,其中包含 checked =checked selected =selected value =blah等您发送此文件。


  • 你的PHP / whatever文件输出一个静态参考文件。您的HTML文件具有JavaScript引用和使用存储在此文件中的值。您可以发送这两个文件(尽管值更新只需要更改的静态引用文件)。



Now, this requirement may seem weird. But i would like to know how to achieve this?
I am having an HTML file, which is having few input box, check box, radio button etc. I would like to retain the changes a user [ actually i ] performs on this page. Like if the user has ticked a checkbox then next time anybody open that file should see that checkbox as ticked.

This thing can be done easily using HTTP cookies. But i don't want to use cookies.
The answer can be as simple as "No you can not do that" :)

Edit
That's the problem with not phrasing the question correctly.

I guess i can't use DB as if i will send my HTML page to someone then he/she will not be able to see my changes. I want my changes to be reflected on other systems also. [ thats the reason i was not going for cookies ]. Other solution what i was thinking was, using FileSystemObject. Any other solution ? again the answer can be "No you can not do that" :D

解决方案

You could bind the change events of your form elements to an AJAX submit, log the submits to the db and then on any page load grab the latest states from the db for rendering.

Edit

If you want these changes to appear "simultaneously" for other users then you could use jQuery polling to update the page - have the page periodically poll the server for the latest state.

Having said that, if you give them a server link and not the actual file they will see your db changes.

However, it sounds like you want to actually send the file (not send someone to a web server) in which case you could do something like one of these approaches:

  • Your PHP/whatever file (can possibly even do this with javascript) outputs a HTML file with appropriate checked="checked", selected="selected", value="blah" etc. You send this file.

  • Your PHP/whatever file outputs a static reference file. Your HTML file has javascript referencing and using the values stored in this file. You send both of these files around (although value updates only require a changed static reference file).

这篇关于如何保存HTML页面的输入值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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