The local storage function provided by HTML5 allows web applications to store data in the user's local browser. In HTML5, data is not passed by every server request, but data is only used when requested. It makes it possible to store large amounts of data without affecting website performance.
There are two methods of storing on the client side:
1. localStorage: Storage with no time limit and large capacity, at least 5M in size; all pages with the same domain name can store and obtain the same data.
2. sessionStorage: For data storage of a session, the tab will disappear when it is closed.
At present, most browsers already support HTML5 very well, but for the sake of security, client detection should be done before use:
if (typeof(Storage) !== undefined) { // Code for localStorage/sessionStorage.} else { // Sorry! No Web Storage support..}
The reason why I use this function is because I am currently working on a data-based website. I need to pass the query parameters to the backend through the API interface and obtain the data returned from the database. There is a problem here. I want to jump from page a to page b, and then call the API interface on page b to pass the parameter data to the background and obtain the data. The parameter data is obtained on page a. So how do I transfer page a to page a? What about passing the generated value to page b?
Assume that the value and data format we want to pass to the background is: {unitGroup:[一年级,二年级,三年级];
Then after page a generates the data unitGroup we need, use sessionStorage:
if (typeof(Storage) !== undefined) { sessionStorage[unitGroup] = data.unit.value;} else { sessionStorage[unitGroup] = '';}
Then on page b, you can get it through the following statement:
var unit_group = '';if (typeof(Storage) !== undefined) { var myunits = sessionStorage[unitGroup]; unit_group = myunits.split(,);}
Then you can call ajax to pass the data to the background:
var newData = {unitGroup: unit_group};
The above is the entire content of this article. I hope it will be helpful to everyone’s study. I also hope everyone will support VeVb Wulin Network.