1

Android プラットフォームでのログインに問題があります。次のコードは、私の cordova phonegap ビルドでログオンするために使用されます。Apple デバイスは問題なく動作し、問題なくログインできます。Android デバイスはすべて、2 回目の試行でログインします。

Android デバイス:

Android デバイスで初めてログインすると、次のエラーが表示されます。

Synchronous request timed out after 10 seconds for the 0th try, URL: 
Synchronous request timed out after 10 seconds for the 1th try, URL: 
Synchronous request timed out after 10 seconds for the 2th try, URL: 

Androidでの2回目の試行で、試行が成功し、サーバーから返されたxmlデータを読み取り、アプリにデータを入力してから、正しいページに変更します.

Apple デバイス:

Apple デバイスがアプリを起動し、試行が成功すると、サーバーから返された xml データが読み取られ、アプリにデータが入力され、正しいページに変更されます。

function login(){
    'use strict';
    var user = document.loginForm.username.value;
    var pwd = document.loginForm.password.value;
    var db = window.openDatabase("MobileDB", "3.0", "MobileDBData", 1000000);
    var loginSuccess = 0;
    console.log("setting user cookies with user name and password: " + user + ", " + pwd);

        // test for ipod/iphone/ipad
        var isiDevice = /ipad|iphone|ipod/i.test(navigator.userAgent.toLowerCase());
        // test for android device
        var isAndroid = /android/i.test(navigator.userAgent.toLowerCase());
        // retrieve the cookie from login

        if (isiDevice)
        {
            $.cookie('username', user);
            $.cookie('password', pwd);
        }
        else if (isAndroid)
        {
            window.localStorage.setItem('username', user);
            window.localStorage.setItem('password', pwd);
        }

        loginSuccess = ReadXML();
        console.error("Login Success after read XML " + loginSuccess);



}

正しいユーザー名とパスワードを取得しましたが、Android デバイスの場合は、2 回のログインが必要です。

function ReadXML() {
    'use strict';

    console.log("begin read xml");
    var url, isiDevice, isAndroid,userId,password,returnStatus;
    url = 'a url';

    // test for ipod/iphone/ipad
    isiDevice = /ipad|iphone|ipod/i.test(navigator.userAgent.toLowerCase());
    // test for android device
    isAndroid = /android/i.test(navigator.userAgent.toLowerCase());

    // retrieve the cookie from login
    if (isiDevice) {
        console.log("found an ipod, iphone, or ipad device");
        userId = $.cookie('username');
        password = $.cookie('password');
    } else if (isAndroid) {
        console.log("found an android device");
        userId = window.localStorage.getItem("username");
        console.log(userId);
        password = window.localStorage.getItem("password");
        console.log(password);
    }

    returnStatus = 0;
    console.log("reading xml with username and password: " + userId + ", " + password);
    var authorizationToken = "Basic " + userId + ":" + password;
    $(document).ready(function () {
                      $.ajax({
                             type: "POST",
                             beforeSend: function (request) {
                             request.setRequestHeader("AUTHORIZATION", authorizationToken);
                             },
                             async: false,
                             url: url,
                             dataType: "xml",
                             success: function (xml) {
                             returnStatus = 1;
                 console.error("Its Working");
                // do stuff 
                             },
                             error: function (x, status, error) {
                             returnStatus = 0;
                             console.error("Its broken");
                // do stuff

                           }
                        });
                      });
    return returnStatus;
}

どんな助けでも大歓迎です。

4

1 に答える 1

4

async: false問題です。Android では、10 秒以上かかる同期呼び出しを行うことはできず、このタイムアウトを変更する方法はありません。で試してくださいasync:true

于 2013-08-02T07:28:40.883 に答える