jquery-based access to WebService code (accessible Java[xfire]) _jquery

Source: Internet
Author: User
Tags soap svn wsdl
I took a closer look at several examples of people and found the problem. It is well known that WebService is compliant with the SOAP protocol, so why are examples of parameter passes in JSON format? NET WebService compatible JSON format, while Java is Standard WebService, incompatible with JSON. It seems that net has harmed everyone. So I took a closer look at the WSDL file and made an example. The key code is placed below.
Copy Code code as follows:

$ (function () {
$ ("#btnWs"). Click (btnajaxpost);
});

function Btnajaxpost (event) {
$.ajax ({
Type: "POST",
ContentType: "Text/xml",
URL: "Http://*****/webservicetest/services/helloworldservice",
Data:getpostdata (),//This should not be in JSON format
DataType: ' xml ',//Here is set to XML or not. Setting the JSON format will make the return value NULL
Success:function (XML) {
Make XML parsing of the results.
Browser judgment (ie and non ie are completely different)
if ($.browser.msie) {
$ ("#result"). Append (Xml.getelementsbytagname ("Ns1:out") [0].childnodes[0].nodevalue+ "<br/>");
}
else{
$ (XML). Find (' out '). each (function () {
$ ("#result"). Append ($ (this). Text () + "<br/>");
})
}
},
Error:function (x, E) {
Alert (' ERROR: ' +x.responsetext);
},
Complete:function (x) {
Alert (' Complete: ' +x.responsetext);
}
});
}
Defines the parameters that satisfy the SOAP protocol.
function Getpostdata ()
{
According to the WSDL parsing SayHelloWorld is the method name, parameters is the passed-in parameter name
var postdata= "<?xml version=\" 1.0\ "encoding=\" utf-8\ "?>";
postdata+= "<soap:envelope xmlns:xsi=\" http://www.w3.org/2001/xmlschema-instance\ "xmlns:xsd=\" http:// Www.w3.org/2001/xmlschema\ "xmlns:soap=\" http://schemas.xmlsoap.org/soap/envelope/\ ">";
postdata+= "<soap:body><sayhelloworld xmlns=\" http://tempuri.org/\ ">";
postdata+= "<parameters>" +$ ("#txtName"). Val () + "</parameters>";
postdata+= "</sayHelloWorld></soap:Body>";
postdata+= "</soap:Envelope>";
return postdata;
}

Complete Example SVN address: http://theyounglearningmaterials.googlecode.com/svn/trunk/JavaWebServices/WebServiceTest/
All the examples I have learned in the future will be put in the http://theyounglearningmaterials.googlecode.com/svn/trunk/to facilitate management to prevent loss.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.