Javascript 如何将令牌保存到本地存储
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27444403/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to save Token to Local Storage
提问by Boba
I'm working on a log in system for an app in school. I can register a user that gets saved to my azure documentDB. I can then, sort of log in with the user. But it (the Token) never gets saved so that I can access the token..
我正在为学校应用程序开发登录系统。我可以注册一个保存到我的 azure documentDB 的用户。然后,我可以与用户一起登录。但它(令牌)永远不会被保存,所以我可以访问令牌..
The script for the log in looks like this:
登录脚本如下所示:
var signin = function() {
var tokenUrl = "http://localhost:15746/Token";
var loginData = $("#userSignup").serialize();
loginData = loginData + "&grant_type=password";
$.post(tokenUrl, loginData).then(navigateToEvent);
return false;
}
$("#signup").click(signin);
How could I store the Token? In Local Storage? How?
我如何存储令牌?在本地存储?如何?
Thanks in advance.
提前致谢。
回答by Andreas Argelius
To save a string in Local Storage you use
要将字符串保存在您使用的本地存储中
window.localStorage.setItem(key, value);
You can get the value later with:
您可以稍后通过以下方式获取该值:
window.localStorage.getItem(key);

