Authentication in jQuery Mobile and PhoneGap

后端 未结 3 1873
北荒
北荒 2021-02-10 08:27

I have a web application built with jQuery Mobile and PHP (CodeIgniter framework). Now I\'m trying to make a PhoneGap version of it as well, to make it distributable as a standa

3条回答
  •  温柔的废话
    2021-02-10 08:52

    The reason your form is still submitting and it's trying to change pages is because you have a syntax error in your submit handler Javascript. On line two, event is not defined so trying to call event.preventDefault() errors. Although the handler fails, the browser still submits the form using it's default action and method.

    Either change your function signature to function(event) { or simply return false from the function. Returning false is equivalent to preventing default.

    $('#login_form').bind('submit', function () {
    
        //send a post request to your web-service
        $.post('http://localhost/app_xcode/account/login', $(this).serialize(), function (response) {
            //check if the authorization was successful or not
            if (response == true) {
                $.mobile.changePage('#toc', "slide");
            } else {
                alert('login failed');
                $.mobile.changePage('#toc', "slide");
            }
        }, 'JSON');
    
        return false;
    });
    

提交回复
热议问题