Note that the data in the Localstorage is Fu, and the Json.parse conversion is used.
Ideas are as follows:
1, read the cached data, for example, called Data_cache
2 Judge Data_cache,if (!data_cache) {Access interface, get data, string json.stringify to the local name Data_cache, and then recursively return the function name}
3 Else parse the data string and then handle it.
For example:
//gets the first-level categorical data and saves it to a localfunctionget1category () {Appcan.window.openToast ("Desperate load data ...", 20000, 5, 1); varData_cahe = Getlocval (' get1category ')); if(!Data_cahe) {Appcan.ajax ({Url:apiurl+ ' standard1category.action ', type:"GET", datatype:"JSON", timeout:30000, Ajaxcache:true, Success:function(data, status, Requestcode, Response, XHR) {data2=json.stringify (data); Setlocval (' Get1category ', data2); Get1category ();//Recursive invocation}, Error:function(XHR, Errotype, error, msg) {Appcan.window.openToast ("Failed to get primary categorical data", 1000, 5, 0); } }); }Else{ //alert (Data_cahe);data =Json.parse (Data_cahe); Data=json.parse (data); if(Data.code = = ' 1 ') { varCate =Data.data; varstr = "; STR+ = ' <table class= "ULA tx-c" border= "0" cellspacing= "0" style= "color: #fff;p adding-right:1.75em;font-size:1.125em" > 'Str+ = ' <tr id= "Cate2" style= "width:100%" > "Str+ = ' <td><div class= "btn2 title1 active1" id= "index" > Recommended </div></td> '; for(vari = 0; i < cate.length; i++) {str+ = ' <td><div class= ' btn1 title ' + (i + 2) + ' onclick= ' goSc2 (\ ' + cate[i].id + ' \ ', \ ' + cate[i].name + ' \ ', 1) "> ' + cate[i].name + ' </div></td> '; } STR+ = ' </tr> 'Str+ = ' </table> ' $(' #scroller '). html (str); Nav_weight (); SCROLLX (); }}}
Cache optimization with Localstorage