1

I have Android 4.0.4 and a PhoneGap 3.6.3 app that makes a synchronous XmlHttpRequest:

var xhr = new XMLHttpRequest();
xhr.open('GET', 'http://myserver/myapp/api/ProgramOptions', false);
xhr.setRequestHeader("Accept","application/json");
xhr.send(null);
window.alert(xhr.responseType);
window.alert(xhr.readyState);
window.alert(xhr.statusText);
window.alert(xhr.status);
window.alert(xhr.responseText);
window.alert(xhr.getAllResponseHeaders());

When loading the web app in the browser, I get

""
4
"OK"
200
"{"success":true,data:[/*snip*/]}"
"Pragma:no-cache
Date:Tue, 17 Feb 2015 09:40:45 GMT
Content-Encoding:gzip
WWW-Authenticate:Negotiate oYG2MIGz/*snip*/
Server:Microsoft-IIS/7.5
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET
Persistent-Auth:false
Vary:Accept-Encoding
Content-Type:application/json; charset=utf-8
Access-Control-Allow-Origin:*
Cache-Control:no-cache
Content-Length:10586
Expires:-1"

When loading the phonegap app, I get

""
4
""
0
""
""

Does anyone know why that is? I already searched for status 0, but there's helluva lot of reasons, and none I found - except the cross-origin requests - comes with an empty responseText. But then, the config.xml contains <access origin="*" />, and, as you can see, the server also sends a Access-Control-Allow-Origin header, so there should be no issue with CORS!?

Alexander
  • 19,906
  • 19
  • 75
  • 162
  • 2
    this might help http://stackoverflow.com/a/11233086/3556874 – Naeem Shaikh Feb 17 '15 at 10:16
  • I found that already, but I can't see how "sometimes getting status 0, but a valid responseText" matches "always getting status 0 and empty responseText". The problem Michael Potter has may be the same that I have, but there is no solution given in that post. – Alexander Feb 17 '15 at 12:43
  • well... it was just **might help you** link, and not for possible duplicate – Naeem Shaikh Feb 17 '15 at 12:45

0 Answers0