GAP Phone SessionStorage

I am working on an iPhone application using a GAP phone. In my application, we use external login to DB.User using a web service, I need to save the user ID after logging in. How can I store a user ID using a GAP phone. Can I use a GAP Session Storage phone for this is possible?

Anyone know, please help.

Thanks, Companion.

+6
iphone cordova
source share
5 answers

You really don't have the concept of “session” in Phonegap - you have HTML5 localStorage for storing persistent data (think of “application area”):

var userId = localStorage.getItem("userId"); if (userId==null || userId==0) { jQT.goTo("#login"); } 

Register 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; 

});

+12
source share

Lawnchair is probably too crowded just for storage and identification, just use HTML5 local storage .

+9
source share

You can try lawnchair to store data as JSON.

+3
source share

There is a concept of SessionStorage. It works the same as localStorage, but it gets wiped out every time you close the application

 var keyName = window.sessionStorage.key(0); //Get key name window.sessionStorage.setItem("key", "value"); //Set item var value = window.sessionStorage.getItem("key");// Get item window.sessionStorage.removeItem("key"); //Remove Item window.sessionStorage.clear();//Clear storage 
0
source share

You can configure session storage this way

 var userid = 10; sessionStorage.setItem('UserId',userid); 

You will get this session variable as such

 var data = sessionStorage.getItem('UserId'); 

Note. This variable will reset after closing the application, but if you want to save to localstorage, you will need the localStorage function, which will not reset after closing the application

0
source share

All Articles