Hamid
Hamid

Reputation: 129

send xml body using webservice

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

Answers (3)

Stewart Mbofana
Stewart Mbofana

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

We0
We0

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

Greentree79
Greentree79

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

Related Questions