I working on an iPhone Application using phone GAP.In my app we are using an external DB .User login using web service, i need to store user ID after login .How i store the user ID using phone GAP.can i use phone GAP Session Storage for this?is possible?
Any one knows please helps.
Thanks, Companion.
setItem() The setItem() method of the Storage interface, when passed a key name and value, will add that key to the given Storage object, or update that key's value if it already exists.
SessionStorage is used for storing data on the client side. Maximum limit of data saving in SessionStorage is about 5 MB. Data in the SessionStorage exist till the current tab is open if we close the current tab then our data will also erase automatically from the SessionStorage.
Session storage is a popular choice when it comes to storing data on a browser. It enables developers to save and retrieve different values. Unlike local storage, session storage only keeps data for a particular session. The data is cleared once the user closes the browser window.
You really don't have the concept of "session" in Phonegap - you have HTML5 localStorage to store persistent data (think "application scope"):
var userId = localStorage.getItem("userId");
if (userId==null || userId==0) {
jQT.goTo("#login");
}
Log user in:
$('#btnLogin').click(function(){
$("#loginFailure").hide();
$.getJSON(svcUri + "authenticate.cfm?username="+$("#username").val()+"&password="+$("#password").val() + "&callback=?",function(data) {
localStorage.setItem("userId",data.userid);
userId = data.userid;
if (data.userid != 0) {
// do some tasks after logging in
jQT.goTo('#travelz');
} else {
$("#loginFailure").show();
}
});
return false;
});
Lawnchair is probably overkill just to store and ID, just use HTML5 local storage.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With