Jquery Ajax and XMLHTTPRequest not working on Phonegap Android

2,046 views
Skip to first unread message

lee

unread,
Jun 11, 2012, 11:13:00 PM6/11/12
to phonegap
Hi

I went through several posts regarding this but couldn't make my code
working one. I am trying call a SOAP webservice deployed on my machine
through Phonegao but Eclipse Android Simulator doesn't work. I tried
giving permissions for cross domain in xml but that did not work
still. Please let me know how to use POST request to SOAP and REST web
services as using phonegap as JQuery Ajax is not working.

I tried the following

1)
var agencyXML = '<?xml version="1.0" encoding="utf-8"?>'+
'<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/
soap/envelope/"\
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="\
http://www.w3.org/2001/XMLSchema-instance">'+
'<soapenv:Body>'+
'<helloName xmlns="http://t320.open.ac.uk">'+
'<name>lee</name>'+
'</helloName>'+
'</soapenv:Body>'+
'</soapenv:Envelope>';

agencyReq.open("POST", "http://10.169.205.42:12432/Hello/
services/Hello",true,"","");
agencyReq.setRequestHeader("Content-Type", "text/xml");
agencyReq.setRequestHeader("SOAPAction","http://
t320.open.ac.uk" + "helloName");
agencyReq.setRequestHeader("Content-Type", "application/xml");
agencyReq.setRequestHeader("Content-
Length",settings.requestData.length);
agencyReq.setRequestHeader("Connection", "close");
agencyReq.onreadystatechange = processAgency;
agencyReq.send(agencyReq);

2)
$.support.cors = true;
.$ajax({type: "POST",
url: "http://10.169.205.42:12432/Hello/services/Hello",
callback: function(data){alert(data);},
error:function(status){alert(error;)},
type:"application/xml",
data:agencyXML});

filmaj

unread,
Jun 12, 2012, 1:59:50 PM6/12/12
to phonegap
did you add the remote server name / IP to your whitelist?

http://docs.phonegap.com/en/1.8.0/guide_whitelist_index.md.html#Domain%20Whitelist%20Guide

Simon MacDonald

unread,
Jun 12, 2012, 3:04:51 PM6/12/12
to phon...@googlegroups.com
It looks like it may be a bug in Android via this thread:

https://groups.google.com/forum/?fromgroups#!searchin/phonegap/problem$20with$20xmlhttprequest$20on$20android/phonegap/bI1Q8l9wAzc/NQwpTFEb3vEJ

Simon Mac Donald
http://hi.im/simonmacdonald
> --
> 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

John C Kendall

unread,
Jun 12, 2012, 3:05:34 PM6/12/12
to phon...@googlegroups.com
If you are targeting android 2.3 then you'll need to remove the Content-length header. There is apparently a bug which prevents android from even sending the request when that header is set. It is really devious too because it does not raise an error and it calls onreadystatechange with a status of DONE and no error...

lee

unread,
Jun 12, 2012, 10:30:11 PM6/12/12
to phonegap
Thanks to all for your replies !!!!!!
Reply all
Reply to author
Forward
0 new messages