[英]Saving app state in jQuery mobile
I have done a bit of research on how to do this but can't find any.I have an app that has a Home
page.On this homepage, there is a Register
button.I want to implement a system where if the user clicks on this and registers, the app never starts with the Register
button displayed again,but rather, a view Profile
button.How do i implement such a system? 我已经做了一些研究如何做到这一点,但找不到任何。我有一个有Home
的应用程序。在这个主页上,有一个Register
按钮。我想实现一个系统,如果用户点击在这个和寄存器上,应用程序永远不会再次显示“ Register
按钮,而是view Profile
按钮。如何实现这样的系统? My guess is to store some boolean value in localstorage, and check this value when the app starts? 我的猜测是在localstorage中存储一些布尔值,并在应用程序启动时检查此值?
Update: I just thought i'd add that my jquery mobile app communicates with a Google App Engine (Python) web service which already uses Google's User's Service
更新:我只是想添加我的jquery移动应用程序与已经使用Google User's Service
的Google App Engine(Python)Web服务进行通信
I believe you are looking for Local Storage Jquery Mobile . 我相信您正在寻找Local Storage Jquery Mobile 。
You have to store data when user click on Register
button, and every time when app will open it checks is there is any data in Local Storage
. 当用户单击“ Register
按钮时,您必须存储数据,每次应用程序打开时,检查“ Local Storage
是否有任何数据。 Then you can use your logic. 然后你可以使用你的逻辑。
You can also use HTML5 Local Storage with Jquery Mobile . 您还可以在Jquery Mobile中使用HTML5本地存储 。 But some device browser dose not support Local storage if you want to check this you should go for Modernizer . 但是有些设备浏览器不支持本地存储,如果你想检查一下你应该去找现代化器 。
This is simple code of checking local storage using modernizer: 这是使用modernizer检查本地存储的简单代码:
if (Modernizr.localstorage) {
// Supported
}
else {
// Not Supported
}
If you only store a boolean after the user is logged-in, yes you know that a user is logged in but you don't know which one. 如果您仅在用户登录后存储布尔值,则表示您知道用户已登录但您不知道哪一个。
Te best approach is to store the user's token which you will send as a parameter in all requests so that you can validate them. 最好的方法是存储用户的令牌 ,您将在所有请求中将其作为参数发送,以便您可以验证它们。
When entering the website if there is a token you must validate it by querying the server. 如果有令牌进入网站,则必须通过查询服务器对其进行验证。 If it's not valid then you show the register/login page. 如果它无效,则显示注册/登录页面。 If the token is valid you could login the user automatically. 如果令牌有效,您可以自动登录用户。
Whatever plugin you decide to use be sure to check that if it is a localStorage plugin it also has fallback for cookies. 无论你决定使用哪种插件,一定要检查一下,如果它是一个localStorage插件,它也有cookie的后备。 (Maybe some clients will have browsers that don't support localStorage) (也许有些客户会有不支持localStorage的浏览器)
On this page there are 3 functions that I personally use when I need access to cookies. 在此页面上,当我需要访问cookie时,我个人使用了3个功能。
Here you have some details about token authentication. 这里有一些关于令牌认证的细节。
I would advise you to store the token using cookies. 我建议你使用cookies存储令牌。
This answer describes one of the best ways of managing user sessions based on tokens. 此答案描述了基于令牌管理用户会话的最佳方法之一。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.