Question

I am creating an app in which I need a session to store the userId which i can use later for fetching data from the datadase. I am new to phonegap Android apps and dont have any knowledge about sessions.So can any one give me some example or link from where I can understand how to create session and use it. Thanks in advance. here is the js code:

ftable=results.rows.item(i).from_table;//from database i am getting to know from which table to call for the select data option in dropdown list
if(ftable.indexOf('#')=='-1'){
from_Table=ftable;
}else{
//**in the from_table there is query which will need session data **//
//  from_Table="(select i.industry_id, i.industry_name, i.deleted, i.comp_code from user_industry_asso cuia, industry i where i.industry_id = cuia.industry_id and cuia.user_id = '1' order by i.industry_name)";
from_Table="";
split_table=ftable.split('#');


alert("Length: "+split_table.length);
for(var k=0;k<split_table.length;k++){
    alert("After split: "+split_table[k]);
    if(k%2==1){
        from_Table +=eval(split_table[k]);
        alert("For loop if condition: "+from_Table);
    }else{
        from_Table +=split_table[k];
        console.log("Else condition: "+from_Table);
    }
}   
}
var select_optionData1="select "+optionName+"," +optionValue+" from "+from_Table+" alias where deleted='0' and comp_code='1' order by "+optionName;
tx.executeSql(select_optionData1,[]);//will get the data from the table and store in array object which will be called later to create a dropdownlist

here is the session which i create in the html file:

var userid='1';
 window.sessionStorage.setItem('ls_userid',userid);

 var userId = window.sessionStorage.getItem('ls_userid');
Was it helpful?

Solution

For Store Session you can use localStorage Follow this link

window.localStorage.setItem('ls_userid',userid);
var userid = window.localStorage.getItem('ls_userid');
console.log(userid);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top