0

I'm developing an app in PhoneGap+dreamweaver cs5.5, who makes a call to a handler (.ashx) and returns a JSON string. I do the following:

function appReady(){
var ajax = new XMLHttpRequest();
    ajax.open("GET","https://xxxx.xxxxx.com/xxxx/xxxx.ashx?method=GetUser&email=xxx@xxxx.com&pwd=123456",false);
    ajax.send();
    ajax.onreadystatechange=function(){
        if(ajax.readyState == 4) {//Request complete !!
            if (ajax.status == 200 || ajax.status == 0) { // OK response
                alert(ajax.responseText);
                document.getElementById('main').innerHTML = ajax.responseText;
            }
        }
    }
}

When I running the app on the iphone emulator, I recover the json string responseText, but this comes empty on android emulator. In iphone the status returned is 200 but in android is 0. if the problem was the coss-domain request, wouldn't work on any platform right?

I don't understand why the example of the wiki: http://wiki.phonegap.com/w/page/42450600/PhoneGap% 20Ajax% 20Sample

works correctly in two platforms and mine only in iphone ...

xvicient
  • 81
  • 2
  • 5

1 Answers1

2

Check for cross-domain scripting issues. I did almost the same thing, except my URL was actually located on the same domain. It worked fine on Android and on a PC, but the iphone refused to function. When I changed from 'https://whatever.whatever.com/foo.asp' to just foo.asp - it worked!

var rootpath;
rootpath = "https://the.same.dam.place/foo.asp";   // did not work!
rootpath = "foo.asp";   // shortening it worked.
function read_foo(whatever)
{
    var url = rootpath + "?whatever=" + whatever;
    xmlHttp = GetXmlHttpObject(stateChanged);
    xmlHttp.open("GET", url , true);
    xmlHttp.send(null);
}
function stateChanged()
{
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
        var return_place = document.getElementById('return_place');
        var thetext = xmlHttp.responseText;
        return_place.innerHTML= thetext;
    }
}

also see:

Empty responseText from XMLHttpRequest

Community
  • 1
  • 1