PhoneGap的Andr​​oid设备准备好,但没有阿贾克斯 [英] PhoneGap Android Device Ready but no Ajax

查看:186
本文介绍了PhoneGap的Andr​​oid设备准备好,但没有阿贾克斯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道我的问题是我的AJAX调用的是HTTP,HTTPS没有。我必须调用以https或我可以使用HTTP调用?

I wonder if my problem is my ajax call is to http, not https. Must I call with https or can I call with http?

我与PhoneGap的云CLI-5.2.0编译(的iOS 3.9.1 / 4.1.1的Andr​​oid / Windows的3.8.1)

I am compiling with PhoneGap cloud cli-5.2.0 ( iOS 3.9.1 / Android 4.1.1 / Windows 3.8.1)

我编译我的包,我的三星Android的安装,它开始了,我的$就错误

I compile my package, install it on my Android Samsung, it starts up, and my $.ajax errors

errorThrown:未定义 textStatus:错误 数据:{的readyState:4​​的responseText:,状态: 404 ,状态文本:未找到}

errorThrown:undefined textStatus:error data:{"readyState":4,"responseText":"","status":404,"statusText":"Not Found"}

任何建议/想法?

我阅读以下内容: jQuery Mobile的+ PhoneGap的Andr​​oid上 - 没有阿贾克斯但其两岁它涉及的PhoneGap的旧版本。

I read the following: jQuery Mobile + Phonegap on Android - no Ajax but its two years old and relates to an older version of phonegap.

我的code并不需要特别的魔法 - 我做的包括phonegap.js,但我不使用GPS,摄像头,联系人等等等等

My code requires no special magic - I do include phonegap.js but I do not use gps, camera, contacts etc etc

使用下面的code,我得到我的deviceready和文件准备好显示。当我点击我的登录按钮(ID ='demologin')函数DemoLogin()被执行。

Using the code below, I do get my "deviceready" and "document ready" displayed. When I click on my login button (id='demologin') the function DemoLogin() is executed.

function onDeviceReady() {
    $("#demologin").on("click", DemoLogin );

    $("#demologin").after("<h3>deviceready</h3>");
    return true;
}

    $(document).ready(
    function()
    {
        document.addEventListener("deviceready", onDeviceReady, false);
        $("#demologin").after("<h3>document ready</h3>");
    });

如果我是猜的AJAX404使我相信它调用了一个不存在因此为什么我想知道Android的希望我叫HTTPS而不是HTTP的URL。这个问题我有,这是code适用于iOS的,所以我还以为PhoneGap的魔法将导致我相信,如果它运行在一个,它会运行在其他的。

If I were to guess, the ajax "404" leads me to believe its calling a URL that does not exist hence why I wonder if Android expects me to call https instead of http. The problem I have with this is the code works on iOS so I would have thought PhoneGap magic would lead me to believe if it runs on one, it would run on the other.

所有帮助AP preciated!

All help appreciated!

推荐答案

我解决了这个问题,我的认为的它不得不做precedence。

I resolved the problem and I believe it had to do with precedence.

这是奇怪的是,URL和完全相同的code。关于我的旧iPad2的工作,但不是我的新的三星Galaxy Tab 4,我怀疑我的javascript函数的顺序在两个环境中完成不同的,因而不同的结果。我并没有完全虽然测试这个理论。

It was strange that URL and exact same code worked on my older iPad2, but not on my newer Samsung Galaxy Tab 4. I suspect the order of my javascript functions completed differently on both environments, thus different outcome. I did not test this theory completely though.

经过多次试验和错误和误解,我把Hello World的脚本的一个副本的PhoneGap和两台设备上进行了测试。这两种工作。

After much trial and error and misunderstanding, I took a copy of the "Hello World" script from PhoneGap and tested it on both devices. Both worked.

我创建功能BindMyEvents(),并添加到它的点点滴滴,测试环境的两台设备上,和所有的工作。请参阅下面的Hello World脚本的一个副本,并通知在那里我称之为BindMyEvents();

I created function BindMyEvents() and added to it bit by bit, testing the environment on both devices, and all worked. See a copy of the Hello World script below, and notice where I call "BindMyEvents();"

我希望这可以帮助别人前进......

I hope this helps someone going forward...

var app = {
// Application Constructor
initialize: function() {
    this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
    document.addEventListener('deviceready', this.onDeviceReady, false);
    BindMyEvents();
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicitly call 'app.receivedEvent(...);'
onDeviceReady: function() {
    // console.log("device ready");
    app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
receivedEvent: function(id) {
    var parentElement = document.getElementById(id);
    var listeningElement = parentElement.querySelector('.listening');
    var receivedElement = parentElement.querySelector('.received');

    listeningElement.setAttribute('style', 'display:none;');
    receivedElement.setAttribute('style', 'display:block;');

    // console.log('Received Event: ' + id);
}
};

这篇关于PhoneGap的Andr​​oid设备准备好,但没有阿贾克斯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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