jqueryajaxjsonmobilejqmobi

Ajax response end Jqmobi


I'm using the jqMobi framework for a web application. In my app, I connect to the server, send username and password and receives a string like this:

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

I get the response, but then it stops.

My code is:

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; 

Solution

  • Try verifying the server response, it might be timing out. Either use CURL or a tool like HttpWatch.

    Also you can try putting a try/catch around the post. If the error is in jqMobi then you'll likely hit the catch. If the server just isn't returning then you'll just hang at the post and the error is likely server side.