Reputation: 129
Please tell me how to send xml body to web service please show an example.. i would be thank full to you please.....
$j.ajax({
type: "POST",
cache:false,
async: false,
data:{} //xml data send to webservice
url:"webservice/HelloWorld",
dataType :"xml",
contentType:"text/xml",
}).done(function(data) {
console.log(data);
//show XML Data
var xmlData =$j(data).find('HelloWorldResult').text();
alert(xmlData);
});
Upvotes: 0
Views: 2069
Reputation: 182
You can send the xml as a string in the body of the request,but you have to use the XMLHttpRequest object. All the details are in David Flanagan's book JavaScript The Definitive Guide.
An excerpt from the book with an example on how to do it can be found on the following link,
http://www.webreference.com/programming/javascript/definitive4/index.html
I hope it helps.
Thanks.
Upvotes: 0
Reputation: 1149
Firstly, what is your send type and return type? And why XML and not JSON?
$j.ajax({
type: "POST",
cache:false,
async: false,
data:{"xml" : var_xml}
url:"webservice/HelloWorld",
dataType :"xml",
contentType:"text/xml",
}).done(function(data){
console.log(data);
//show XML Data
var xmlData =$j(data).find('HelloWorldResult').text();
alert(xmlData);
});
There you send a variable called var_xml
, in PHP access it with $_POST['xml] and you can return an XML to use in JS.
Though this is very bad practice, rather use json.
Upvotes: 1
Reputation: 1
If your Webservice is PHP, I would send the XML as a string - data:"<xmlNode><child></child></xmlNode>"
then parse it in PHP with something like SimpleXML
Upvotes: 0