真实设备上的cordova/phonegap应用程序中的Ajax请求失败 [英] Ajax request failing in cordova/phonegap app on real device

查看:31
本文介绍了真实设备上的cordova/phonegap应用程序中的Ajax请求失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个 Cordova 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":"", "status":0, "statusText":"error"}

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;,并且我已经拥有 <accessorigin="*"/>) 在我的 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?

推荐答案

嗯,这不是我所期望的那种答案,但我这样做是为了解决这个问题:创建一个全新的 Cordova 4.0 项目并复制到那里www 文件夹从另一个.然后像往常一样在 Eclipse 中构建和运行,一切正常无需更改项目中任何地方的任何一行代码.

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.

我意识到问题不在代码中,因为我注意到我在应用程序中进行的其他 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.

所以我不知道这是 Cordova 4.0 错误还是什么,但在某个时候 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.

这篇关于真实设备上的cordova/phonegap应用程序中的Ajax请求失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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