[英]How to store data in localstorage.setItem(); taht we can access anywhere in project
Here I want to store obj.email
in localStorage.setItem("PMUsername", obj.email);
在这里,我想将
obj.email
存储在localStorage.setItem("PMUsername", obj.email);
that I can access in my project anywhere. 我可以在任何地方访问我的项目。 But I'm not able store the value, it's coming through as
null
. 但是我无法存储该值,它通过
null
传递。
window.plugins.googleplus.login({}, function(obj) {
console.log("Objct", obj);
//$("#logs").append("<p class='success'><b>response: </b>" +localStorage.setItem("value", JSON.stringify(obj)) + "</p>")
localStorage.setItem("value", JSON.stringify(obj));
window.location.href = "login.html";
document.querySelector("#image").src = obj.imageUrl;
document.querySelector("#image").style.visibility = 'visible';
// in below code am displaying email and username value in #feedback i.e <p id="feedback"></p>
document.querySelector("#feedback").innerHTML = "Hi, " + obj.displayName + ", " + obj.email;
localStorage.setItem("PMUsername", obj.email);
}, function(msg) {
$("#logs").append("<p class='error'><b>response: </b>" + msg + "</p>");
});
}
I just need to store that #feedback
value in localstorage.getitem()
, so that I can access anywhere. 我只需要将该
#feedback
值存储在localstorage.getitem()
,以便可以在任何地方访问。 Thanks 谢谢
You cannot set undefined
value to the localStorage
. 您不能为
localStorage
设置undefined
值。
You need to set a string
to the localStorage
as a value. 您需要将
string
设置为localStorage
作为值。
For this, your obj
should contain property email
. 为此,您的
obj
应该包含属性email
。
Documentation on localStorage can be helpful. 有关localStorage的文档可能会有所帮助。
如果没有收到电子邮件,则无法在localstorage中设置undefined。确保控制台中包含电子邮件(console.log(“ Objct”,obj))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.