Authentication in jQuery Mobile and PhoneGap

后端 未结 3 1871
北荒
北荒 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:34

    You can make requests to your web-service (Ion Auth) from your app. with jQuery. Your login would look something like this:

    //add event handler to the `submit` event for your login form
    $('#login_form').bind('submit', function () {
    
        //send a post request to your web-service
        $.post('http://my-domain.com/my-auth/auth.php', $(this).serialize(), function (response) {
    
            //parse the response string into an object
            response = $.parseJSON(response);
    
            //check if the authorization was successful or not
            if (response.status === 'success') {
                //do login here
            } else {
                //do error here
            }
        });
    });
    

    $(this).serialize() will add the login form's data to the post request. This example assumes your web-service will return JSON.

提交回复
热议问题