JQuery-based WebService access code (Java [Xfire] can be accessed) _ jquery

Source: Internet
Author: User
I recently learned JQuery and found many examples of JQuery Accessing. netWebService. WebService interfaces should be generic. Why is there no Java example? This has aroused my interest. I took a closer look at several examples and found the problem. As we all know, WebService complies with the SOAP protocol. Why are parameters transmitted in JSON format in the example? Net WebService is compatible with JSON format, while Java is a standard WebService and is not compatible with JSON format. It seems that net has hurt everyone. So I carefully understood the WSDL file and made an example. Only the key code is shown below.

The Code is as follows:


$ (Function (){
$ ("# BtnWs"). click (btnAjaxPost );
});

Function btnAjaxPost (event ){
$. Ajax ({
Type: "POST ",
ContentType: "text/xml ",
Url: "http: // *****/WebServiceTest/services/HelloWorldService ",
Data: getPostData (), // JSON format is not used here
DataType: 'xml', // set to xml or not set here. Setting it to JSON format changes the return value to NULL.
Success: function (xml ){
// Parse the result in XML format.
// Browser judgment (IE and non-IE are completely different)
If ($. browser. msie ){
$ ("# Result"). append (xml. getElementsByTagName ("ns1: out") [0]. childNodes [0]. nodeValue +"
");
}
Else {
$ (Xml). find ("out"). each (function (){
$ ("# Result"). append ($ (this). text () +"
");
})
}
},
Error: function (x, e ){
Alert ('error: '+ x. responseText );
},
Complete: function (x ){
// Alert ('complete: '+ x. responseText );
}
});
}
// Define parameters that meet the SOAP protocol.
Function getPostData ()
{
// According to the WSDL analysis, sayHelloWorld is the method name, and parameters is the input parameter name.
Var postdata =" ";
Postdata + =" ";
Postdata + =" ";
Postdata + =" "+ $ (" # TxtName "). val () +" ";
Postdata + =" ";
Postdata + =" ";
Return postdata;
}


Complete example SVN address: http://theyounglearningmaterials.googlecode.com/svn/trunk/JavaWebServices/WebServiceTest/
All of my later learning examples will be placed in http://theyounglearningmaterials.googlecode.com/svn/trunk/to facilitate management and prevent loss.
Related Article

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.