Ajax请求没有在真实的设备科尔多瓦/ PhoneGap的应用程序 [英] Ajax request failing in cordova/phonegap app on real device

查看:165
本文介绍了Ajax请求没有在真实的设备科尔多瓦/ PhoneGap的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建一个科尔多瓦4.0 jQuery Mobile的1.4.2 Android应用,我有一个特定的AJAX调用的问题。我已经看过类似的问题,并已经实施的解决方案,也没有成功。

I'm building a Cordova 4.0 jQuery Mobile 1.4.2 Android app and I'm having issues with a particular AJAX call. I've looked for similar questions and already implemented the solutions there with no success.

下面是会发生什么:

我有以下的AJAX调用:

I have the following AJAX call:

var request = $.ajax({
        type: "GET" ,
        crossDomain: true,
        url: 'http://pubads.g.doubleclick.net/gampad/adx?iu=/XXX/YYY&sz=300x50&c=123456789'
    });

    request.done(function (response, textStatus, jqXHR){

        console.log(response);
    });

    request.fail(function (jqXHR, textStatus, errorThrown){
        console.error("DFP Plugin Error: " + textStatus, errorThrown);
    });

当我运行我在我的电脑浏览器的应用程序,这要求完美的作品。然而,当我建立并从真正的设备调试应用程序,则请求失败给这个错误: {readyState的0的responseText:,状态0状态文本:错误}

When I run my app in my computer's browser, that request works perfectly. However, when I build and debug the app from a real device, the request fails giving this error: {"readyState":0, "responseText":"", "status":0, "statusText":"error"}

我已经启用 $ support.cors = TRUE; $ mobile.allowCrossDomainPages = TRUE; ,我已经有<在我的config.xml文件)

I've already enabled $.support.cors = true; and $.mobile.allowCrossDomainPages = true;, and I already have <access origin="*" />) in my config.xml file.

有人能帮助我弄清楚的问题是什么?

Could someone help me figure out what the problem is?

推荐答案

那么,这是不是这样回答我期待的,但是这就是我所做的,以解决此问题:创建一个全新的科尔多瓦4.0项目,并复制那里从其他的一个WWW文件夹。然后建立在Eclipse中像往常一样,一切都运行工作的不改变code单独一行项目中的任何地方

Well, this is not the kind of answer I was expecting, but this what I did to solve this: create a completely new Cordova 4.0 project and copy there the www folder from the other one. Then build and run in eclipse as usual and everything worked without changing one single line of code anywhere in the project.

我意识到这个问题是不是在code,因为我注意到,其他的AJAX调用我的应用程序(并用于正常工作)也失败了。

I realized the problem wasn't in the code because I noticed that other AJAX calls that I had in the app (and used to work fine) were also failing.

所以,我不知道这是不是有些科尔多瓦4.0的bug什么的,但在某些时候AJAX停止工作。我张贴这种万一有人跑进了同样的问题。

So I don't know if this is some Cordova 4.0 bug or something, but at some point AJAX stopped working. I'm posting this in case someone runs into the same issue.

这篇关于Ajax请求没有在真实的设备科尔多瓦/ PhoneGap的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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