2013-08-17 58 views
0

我正在创建一个应用程序,我需要一个会话来存储userId,稍后我可以使用它从数据库中获取数据。我是phonegap的Android应用程序的新手,并没有任何关于会话的知识。所以任何人都可以给我一些例子或链接,我可以从中了解如何创建会话并使用它。 在此先感谢。 这里是js代码:如何在phonegap Android应用程序中创建会话

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 

这里是我在HTML文件中创建会话:

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

var userId = window.sessionStorage.getItem('ls_userid'); 

回答

2

对于存储会话,你可以使用localStorage的Follow this link

window.localStorage.setItem('ls_userid',userid); 
var userid = window.localStorage.getItem('ls_userid'); 
console.log(userid); 
+0

哎我在选择查询中调用此会话#return $ aes-> decrypt($ _ SESSION [“userId”]);#通过在字符串中使用split函数我正在使用eval(from_table [i]);它将替换##之间的字符串,但是当我执行它时,它表示它在logcat中显示错误。08-17 15:46:43.097:D/CordovaLog(4079):未捕获的SyntaxError:意外的令牌> 08-17 15 :46:43.097:E/Web控制台(4079):未捕获的SyntaxError:意外的令牌> at file:///android_asset/www/dynamic_form.html:1 你能告诉它为什么给出错误。 –

+0

请粘贴一些代码 –

+0

为什么你使用evel –

相关问题