0
我該如何恢復本地存儲中的值請幫助我..?我想在不替換現有變量的情況下在localStorage中恢復變量?
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if(xhttp.readyState == 4 && xhttp.status == 200)
{
var data = JSON.parse(xhttp.responseText);
if (data.hasOwnProperty(username.value) && data[username.value]["pass"] === password.value){
saveLocalstorage('task' , JSON.stringify(data[username.value]["task"]));
if(window.localStorage){
location.pathname += "redirect_page.html";
//console.log(JSON.stringify(localStorage));
}else {
localStorage.clear();
}
}
else {
alert("user not available");
}
}
}
xhttp.open('GET',"user.json",true);
xhttp.send()
我想恢復「任務」變量中的值。