简体   繁体   中英

Ajax requests in phonegap projects on android

My dojo based project worked fine with phonegap 2.7.0 but after "upgrade" with phonegap 3.0 none of the ajax requests seem to be getting through.

I created a simple test page with plain javascript (to eliminate dojo as a variable) and the results are the same.

Thanks Mike

My environment

  1. phonegap 3.0
  2. Android 4.1.1 on Galaxy S3, or Android 4.3 on emulator
  3. The < uses-permission android:name="android.permission.INTERNET" /> is present in the manifest
  4. < access origin="*" /> is present in the config.xml

javascript:

    xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange=function(){
      alert ("rdystate: " + xmlhttp.readyState);
      alert ("status: "   + xmlhttp.status);
      alert ("Text: "     + xmlhttp.statusText);
      alert ("ResponseText: " + xmlhttp.responseText);
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
      {
        alert(xmlhttp.responseText);
      }
    }
    xmlhttp.open("GET","http://10.0.2.2:8080/myapp/rest/feedback/ping",true);
    xmlhttp.send();

output:

    rdystate: 1
    rdystate: 2
    status: 404
    Text: *empty*
    ResponseText: *empty*
    rdystate: 4
    status: 404
    Text: *empty*
    ResponseText: *empty*

I'm not 100% sure about this but I believe that using IP addresses may not fall under the domain whitelist? Can you point a DNS record to it and try using the domain name instead?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM