简体   繁体   English

我如何在网页上存储由javascript所做的更改?

[英]How do I have a web page store changes made by javascript?

I have a form on a simple web page that has a series of checkboxes. 我在具有一系列复选框的简单网页上有一个表单。 These options represent items that may be retrieved from a database upon clicking the submit button. 这些选项表示单击提交按钮后可以从数据库检索的项目。 In addition, there is a place to add an extra option to the page at the bottom. 此外,在底部的页面上还可以添加一个附加选项。 Here is what I am going for: 这是我要的:

I would like to be able to add the new option using javascript, so that it show up quickly and seamlessly to the user, rather than having to send the request back to the server and add it server-side, then have the user reload the page. 我希望能够使用javascript添加新选项,以便它可以快速无缝地显示给用户,而不必将请求发送回服务器并在服务器端添加它,然后让用户重新加载页。 However, I also want to make sure that these added fields are preserved so that the next time I load the page, they show up. 但是,我还想确保保留这些添加的字段,以便下次我加载页面时,它们会显示出来。

Unfortunately, my code is proprietary, so I cannot post it here. 不幸的是,我的代码是专有的,因此无法在此处发布。 I hope that people can help me this some ideas without having to actually see the code. 我希望人们可以在不必实际查看代码的情况下为我提供一些帮助。

Thanks 谢谢

When these checkboxes are added you don't want to go the server but when user presses submit you are anyways going to server, so at that time you can persist this information about new checkboxes on server. 添加这些复选框后,您不想进入服务器,但是当用户按下“提交”按钮时,您还是要进入服务器,因此在那时,您可以将有关新复选框的信息保留在服务器上。

Another option is to call to server asynchronously using AJAX to update the server about the state change. 另一个选择是使用AJAX异步调用服务器以更新服务器有关状态更改的信息。

If you still want to store the changes server-side, you can do so quietly in the background. 如果仍要在服务器端存储更改,则可以在后台安静地存储。

Just use XmlHttpRequest() , together with a PHP script. 只需将XmlHttpRequest()与PHP脚本一起使用即可。

您可以使用HTML5本地存储API来存储您的更改。

localStorage.setItem('favoriteflavor','vanilla');

If you want session related information to pass thru multiple requests, you can either put the data in a cookie, or with php you can use sessions. 如果您希望会话相关信息通过多个请求传递,则可以将数据放在cookie中,也可以使用php使用会话。

http://php.net/manual/en/features.sessions.php http://php.net/manual/en/features.sessions.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 每次进行更改时,我真的必须重新启动服务器吗? - Do i really have to restart the server everytime i made changes? 当页面使用Javascript刷新时,如何保持对类所做的更改 - How to keep changes made to a class when the page refreshes with Javascript 如何让 php 知道我在输入中进行了更改? - How do I let php know that I made changes In input? 如何获得在第一页生成的另一个php文件上创建的JavaScript对象? - How do I obtain a JavaScript object that is created on another php file made by the first page? 是否有可能在php中保存在网页上所做的更改而无需发送到数据库中 - is it possible in php to save changes made on web page without sending into database 关闭对话框时,如何使对话框不保存对对话框所做的任何更改? - How do I make the dialog not save any changes I made to inside it when I close it? 如何使用php将图像序列更改存储到mysql数据库 - How do I store image sequence changes to a mysql database with php Magento 2 在管理面板中所做的更改未显示在客户端页面上 - Magento 2 Changes Made in Admin Panel do not appear on the Client's Page 如何在“标准化”中跟踪更改并存储计算的内容? - How do I track changes and store calculated content in Nermalization? 如何使用PHP提交网页? - How do I submit a Web page with PHP?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM