简体   繁体   中英

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. 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.

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.

您可以使用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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM