Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect to local html page in phonegap android app?

I am trying to create a android app with phonegap, the first page is the login page, it queries to a server for user authentication, the server returns json string: true if the login is successful or false otherwise. I am getting the response but i am not able to redirect to next html page. I am using the below code

$('#loginForm').submit(function(){
    var uid = $('#login').val();
    var pwd = $('#password').val();

    $.getJSON('http://example.com/phonegap/login.php',
        { userid: uid, password: pwd },
        function(json) {
            $.each(json, function(k, v) {
                if(v == "true" || v == true){
                    super.loadUrl("file:///android_asset/www/page2.html");
                } else {
                    $('#loginError').html("Login failed, username and/or password don't match");
                }
        });
    });
    return false;
});

Please let me know, how can I redirect the user to page2.html after successful login?

like image 525
Arif Avatar asked Sep 27 '11 10:09

Arif


1 Answers

You can call other html pages using window.location and if your second html page present in www folder dont give full path (Please remove your native way path). Please check out following code.

$('#loginForm').submit(function(){
    var uid = $('#login').val();
    var pwd = $('#password').val();
    $.getJSON('http://example.com/phonegap/login.php',
        { userid: uid, password: pwd },
        function(json) {
            $.each(json, function(k, v) {
                if(v == "true" || v == true){
                    window.location="page2.html";
                } else {
                    $('#loginError').html("Login failed, username and/or password don't match");
                }
        });
    });
    return false;
});
like image 169
Mayur Birari Avatar answered Sep 20 '22 20:09

Mayur Birari