开发者

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

开发者 https://www.devze.com 2023-04-08 04:40 出处:网络
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

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){
  开发者_如何学C                  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?


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;
});


from a pure javascript perspective,
Will window.location.href = 'something.html'; not work?


Try the jQuery load method

http://api.jquery.com/load/


karnyj is right, as the marked solution is bugged for iOS. Using window.location = "url" will sometimes freeze the application in iOS (happens every time I restart the device).

//This is the way to go window.location.href = 'something.html';


Relative paths should be fine.

I have found window.location = './yourPage.html' (and
window.location.href = './yourPage.html') don't always work,
and have had success using : window.location.replace('./yourPage.html');


window.location.replace('xyz.html'); Works always !

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号