Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
945 views
in Technique[技术] by (71.8m points)

jquery - Ajax request failing in cordova/phonegap app on real device

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.

Here's what happens:

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

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...