Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phone GAP SessionStorage

Tags:

iphone

cordova

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.

like image 685
user232751 Avatar asked Jan 05 '11 05:01

user232751


People also ask

What does sessionStorage setItem do?

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.

How much data can sessionStorage hold?

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.

What is 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.


2 Answers

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;

});

like image 115
Billy Cravens Avatar answered Sep 21 '22 08:09

Billy Cravens


Lawnchair is probably overkill just to store and ID, just use HTML5 local storage.

like image 42
Kris Erickson Avatar answered Sep 19 '22 08:09

Kris Erickson