The difference between 1) H5 and localStorage of new sessionStorage
sessionStorage and the session almost java, information can be stored for a short time, the computer browser used sessionStorage store user login information (personal understanding)
localStorage can permanently retain user information, do not always log on, commonly used in the APP
2) method sessionStorage and shared localStorage:
1.setItem stored value
setItem like java in the map, but there are generic <String, String>
sessionStorage.setItem("user",user);
2.getItem Value
sessionStorage.getItem("user");
3.removeItem delete the value
sessionStorage.removeItem("user");
4.clear clear all values
sessionStorage.clear();
3) front-end converter and JSON String
String转成JSON JSON.parse();
JSON转成String JSON.stringify();
These are the basic usage of the new H5 sessionStorage and localStorage, combined with examples will better understand their usage.
code show as below:
// If falg is true, that is correct verification code, send a request to the background IF (== Flag to true ) { $ .post ( "HTTP: // localhost: 8080 / the Test / ADMIN / the Login", {username: the User, password: pwd}, function (Data) { IF (Data) { // the setItem like java Lane put map, but there is generic <String, String> // Data type is JSON, so use JSON.stringify (data) Switch String var S = the JSON.stringify (data); sessionStorage.setItem ( "ADMIN" , S); window.location.href = "index.html" ; } the else {span style = 'color: red;'> swipe codes! ! ! </ Span> " ); setTimeout(function () { $("#msg").html(""); },2000); }
2019-09-09 10:18:45