2012-06-11 17 views
0

我是jquery mobile的新手,我開發了一個包含jquery mobile和phoneGap和localstorage Html的移動應用程序,我想在頁面中保存一個輸入值html的,然後我會再檢索該值withlocalstorage.getitem和網址中使用,我的問題,當我加入這行value=localStorage.getItem('myStorage');我無法連接到我的應用程序,我得到這個錯誤:

表達的結果「 $ .mobile'[undefined]不是一個對象。在 文件:///android_asset/www/js/application.js:258

這是我保存的輸入值 的application.js

function setMessage() { 
    var firstName=document.getElementById('addresseip'); 
    alert("Hello " + firstName.value + ", hope you like JavaScript functions!") 

        localStorage.setItem('myStorage', firstName.value); 

} 

的應用,這是我的呼籲在同一個頁面的.js此值,輸入vaule是param.html並調用這個值是index.html中:

function showUser(){ 
value=localStorage.getItem('myStorage'); 
val1 = document.getElementById("name").value; 
val2 = document.getElementById("pass").value; 

if (val1=="") 
    { 
    showdialog("Verifiez login et mot de passe","Erreur"); 
    } 
    else{ 
    alert("test"+value);  
    $.mobile.showPageLoadingMsg();  
    var geturl; 
    geturl = $.ajax({ 

    url:"https://"+value+":80/B/authenticate", 
    //url:"https://10.0.2.2:80/B/authenticate", 
    dataType:"json", 
    timeout:10000000, 
    cache:false, 
    type:'GET', 
    beforeSend : function(req) { 
      req.setRequestHeader('Authorization', 
        make_base_auth (val1, val2)); 
     }, 
    error:function(XMLHttpRequest,textStatus, errorThrown) { 
    $.mobile.hidePageLoadingMsg(); 
    showdialog("Verifiez login et mot de passe","Erreur"); 
    }, 
    success:function(results) { 
    if(results==true){ 

    $.mobile.changePage("bienvenu.html","fade"); 
    $.mobile.hidePageLoadingMsg(); 
    } 

我的錯誤是一個線$ .mobile.showPageLoadingMsg();

你能幫幫我,謝謝

回答

0

除了加載jQuery,你還應該包括jQM。請確保你的代碼使用jQM包含在它之後。

<script src="//code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script> 
<script src="yourscripts.js"></script> 

<script src="//code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script> 
<script> 
    /* Your code here */ 
</script> 
0

由於$.mobileundefined,我猜測,jQuery Mobile的庫沒有加載。檢查您是否在致電showUser()之前加載了jquery和jquery mobile。

+0

感謝您的答覆,但我不understing我如何加載jQuery和jQuery Mobile的,我有這樣的'<腳本類型= 「文/ JavaScript的」 SRC = 「http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js」>',或者我必須使用其他方法 – julia

+0

這行加載jquery。對於jQuery的移動,你會在文檔中找到答案,請參閱例如:http://jquerymobile.com/>文檔>快速入門指南。 – Claude

相關問題