登录工作为iPhone而不是Android的 [英] Login working for Iphone but not android

查看:109
本文介绍了登录工作为iPhone而不是Android的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的登陆了Android平台的问题。下面code使用我的科尔多瓦的PhoneGap构建登录。苹果设备的工作正常,没有任何问题的登录。在Android设备上的所有第二次尝试登录。

I am having issues with my login with android platforms. The following code is used with my cordova phonegap build to log on. The apple device's work fine and log in without any issues. The android devices all log in on the second attempt.

Android设备:

我第一次用我的Andr​​oid设备上登录,我收到以下错误:

The first time I log in with my android devices i get the following error:

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的第二次尝试,它读取我回去来自服务器的XML数据,填充的应用程序,然后切换到正确的页面。

On the second attempt on the android I get a successful attempt, it reads the xml data that I get back from the server, populates the app and then changes to the correct page.

苹果设备:

苹果设备火起来的应用程序,我得到一个成功的尝试,它读取我回去来自服务器的XML数据,填充的应用程序,然后切换到正确的页面。

the apple device fires up the app, I get a successful attempt, it reads the xml data that I get back from the server, populates the app and then changes to the correct page.

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



}

我得到了正确的用户名和密码,但无论怎样的Andr​​oid设备需要2登录工作。

I get the correct usernames and passwords, but no matter what for the android device it takes 2 logins to work.

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

任何帮助将是很大的AP preciated。

Any help would be greatly appreciated.

推荐答案

异步:假就是问题所在。 Android的犯规让你做一个同步调用它需要超过10秒有没有办法改变这种超时。尝试使用异步:真正的

async: false Is the problem. Android doesnt let you make a synchronous call which takes more than 10 s and there s no way to change this timeout. Try with async:true.

这篇关于登录工作为iPhone而不是Android的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆