2012-11-25 45 views
0

我正在爲web應用程序使用jqMobi框架。在我的應用程序,我連接到服務器,發送用戶名和密碼,並接收一個字符串是這樣的:Ajax響應結束Jqmobi

[{"utoken":"e43aa84cc304a1ed3722832616294516b118a5c2","username":"myusername","sharecode":"testmus","created":"2012-07-17 13:51:32"}] 

我得到的迴應,但隨後停止。

我的代碼是:

function Connectserver() { 
    var form = $("#loginForm");  
    //disable the button so we can't resubmit while we wait 
    $("#submitButton",form).attr("disabled","disabled"); 
    var u = $("#username", form).val(); 
    var p = $("#password", form).val(); 
    alert('knappen bliver klikket') ; //This fires 
     if(u != '' && p!= '') { 

     alert('data sendes') ; //This fires 
     $.post("http://m.myhost.com/service/login.php", {username:u,password:p}, function(data) { 

     alert('renspons retur') ;//This are not fired 

      if(data[0].username == u) { 
       //store 
       alert('renspons retur') // Not fired 
       var utoken = data[0].utoken; 
       localStorage.setItem("utoken", utoken); 
       } 
      else 
       { 
       alert("Dine loginoplysninger er ikke korrekte", function() {}); 
       } 
     $("#submitButton").removeAttr("disabled"); 
     },"json"); 
    } else { 
     alert("Du skal indtaste brugernavn og password", function() {}); 
     $("#submitButton").removeAttr("disabled"); 
    } 
    return false; 

回答

0

嘗試驗證服務器的響應,它可能會超時。使用CURL或HttpWatch之類的工具。

此外,你可以嘗試在帖子周圍試一試。如果錯誤是在jqMobi中,那麼你可能會碰到這種情況。如果服務器沒有返回,那麼你只會掛在帖子上,錯誤可能是服務器端。

+0

感謝您的意見:) 服務器正確返回響應,代碼與jquery mobile協同工作,但與jqmobi協同工作 –

+0

嘗試將其更改爲$ .ajax調用並添加錯誤功能。 – 2012-11-27 13:03:04

+0

立即工作。感謝您的幫助:) –