The actual application returns the loss of data read by ajax in the previous step .. You can save it through the browser cache.
The code is as follows: |
Copy code |
Function saveCity (){ Var province = $ ("# province"). val (); Var city = $ ("# city"). val (); Var area = $ ("# area"). val (); // Alert ("syheng" + province + "chis" + city + "ara" + area ); /* LocalStorage. removeItem ("province "); LocalStorage. removeItem ("city "); LocalStorage. removeItem ("area ");*/ LocalStorage. setItem ('Province ', province ); LocalStorage. setItem ('city', city ); LocalStorage. setItem ('region', area ); } Function loadCity (){ Var province = localStorage. getItem ('Province '); Var city = localStorage. getItem ('city '); Var area = localStorage. getItem ('region '); // Alert ("syheng" + province + "chis" + city + "ara" + area ); If (province! = Null & city! = Null & area! = Null ){ $. Ajax ({ Url: baseUrl + '/getAddressJson. Json ', Data :{ 'Region': area, 'City': city, 'Province ': province }, Type: 'post', // data transmission method Async: false, DataType: "json ", Success: function (data ){ $ ("# Province"). empty (); $ ("# City"). empty (); $ ("# Area"). empty (); $. Each (data. plist, function (index, content) { Var appendStr = "<option value = '" + content. code + "'"; If (content. code = province ){ AppendStr = appendStr + "selected = 'selected '"; } AppendStr = appendStr + ">" + content. name + "</option>" $ ("# Province"). append (appendStr ); }); $. Each (data. clist, function (index, content) { Var appendStr = "<option value = '" + content. code + "'"; If (content. code = city ){ AppendStr = appendStr + "selected = 'selected '"; } AppendStr = appendStr + ">" + content. name + "</option>" $ ("# City"). append (appendStr ); }); $. Each (data. alist, function (index, content) { Var appendStr = "<option value = '" + content. code + "'"; If (content. code = area ){ AppendStr = appendStr + "selected = 'selected '"; } AppendStr = appendStr + ">" + content. name + "</option>" $ ("# Area"). append (appendStr ); }); } }); } } LoadCity (); |
The following is an explanation
① The localstorage size is limited to about 5 million characters. Different browsers are inconsistent.
② Localstorage cannot be read in private mode
③ Localstorage is essentially a file to be read and written. If there is too much data, it will be relatively slow (firefox will import the data into the memory at a time, and it will be scary to think about it)
④ Localstorage cannot be crawled by Crawlers. Do not use it to completely replace URL parameter passing.
Localstorage storage objects can be divided into two types:
① SessionStrage: session refers to the period from when a user browses a website and closes the website, the validity period of the session object is only so long.
② LocalStorage: save the data on the client hardware device, no matter what it is, that is, the data is still in the next time you open the computer.
The difference between the two is temporary storage and long-term storage.