Re: [PhoneGap] AJAX POSTing XML Requests Working on Emulator, But Not Device

378 views
Skip to first unread message

Kerri Shotts

unread,
Jul 19, 2012, 2:13:30 AM7/19/12
to phon...@googlegroups.com
How big is the response that you should get?

_________________________________________
~Kerri Shotts, photoKandy Studios LLC
   Wanna be our neighbor? Our Facebook page & Twitter feed.

On Thursday, July 19, 2012 at 12:54 AM, bmoztalay wrote:

We've been having really weird issues. The gist of it is that we're writing a Phonegap app for Android and iPhone, and we have to use a web service by making POST requests to it with XML, and we get XML back. We can't use JSON or anything like that. So, the requests work in the iPhone emulator (not tested on device), Android emulator (running 2.3.1 and 4.0.3), and Chrome, just to be sure. Only one of them works on the actual Android device, the others don't.

The one that works is the login request, which we make with a standard XmlHttpRequest, like so:

function sendLoginRequestAndWaitForResponse() {
request=new XMLHttpRequest();
request.onreadystatechange = function() {
if (request.readyState == 4) {
                     if (request.status == 200 || request.status == 0) {
                     //Parse the request.responseXML
                            alert(request.responseText);
                     }
                }
}

postdata = "big XML string that we know works";

try {
request.open("POST","http://www.domain.com/location/of/login.cgi",true);
request.send(postdata);
} catch(e) {
console.log(e);
}
}

And the other request is made in the exact same way, just with a different URL to get to a different .cgi script, and a different XML string. When the request is made, it comes back and hits the alert(request.responseText), so we know that everything thinks it worked, but the alert is just blank.

We also tried making the other request using jQuery.ajax, and it works just that same: on everything but the Android device. Here's that code:

function sendOtherRequestAndWaitForResponse() {
postdata="XML string, quintuple checked";
$.ajax({
   data: postdata, 
   type: 'POST',
   contentType: "text/xml",
   dataType: "xml",
   
   success:function(data, textStatus, response) {
    alert(response.responseText);
   },  
        error:function(response, textStatus, errorThrown) {     
    console.log("Error: " + response.responseText);
    console.log("Error: " + response.status);
    console.log("Error: " + response.statusText);
    console.log("Error: " + response.getAllResponseHeaders());
    alert("Error, could not locate vehicle, please try again later.");
   }
});
}

This is a bit different, because it comes back into the error callback. However, all of the fields being logged are either blank or null. response.status is 0, though.

We really have no idea what's going on. I can't understand why it works on all the other platforms, but not the actual device.

And, just for the record, we have done the following:
  1. Put the INTERNET permission in our manifest
  2. Whitelisted the entire internet in cordova.xml with <access origin="*"/>
  3. Made sure we had an internet connection on the phone
  4. Used the most recent version of Phonegap, 1.9
Thanks in advance for the help, let me know if you need any more information.

--
-- You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en
 
For more info on PhoneGap or to download the code go to www.phonegap.com
 
To compile in the cloud, check out build.phonegap.com
 
 

Gregg

unread,
Jul 20, 2012, 11:42:04 AM7/20/12
to phon...@googlegroups.com
I suspect the first one works since there is no specific content-type, thus defaulting to text, and filling responseText. The second is setting content type to XML, which will return responseXML...not responseText, which is what you are displaying.

Giacomo Balli

unread,
Jul 20, 2012, 2:12:13 PM7/20/12
to phonegap
most times, when it works on simulator but not device, it's an issue
with lowercase/uppercase mismatch (device is more strict).
> > we know that everything *thinks* it worked, but the alert is just blank.
> >    1. Put the INTERNET permission in our manifest
> >    2. Whitelisted the entire internet in cordova.xml with <access
> >    origin="*"/>
> >    3. Made sure we had an internet connection on the phone
> >    4. Used the most recent version of Phonegap, 1.9
Reply all
Reply to author
Forward
0 new messages