Home >Web Front-end >JS Tutorial >Code for accessing WebService based on JQuery (accessible to Java [Xfire])_jquery

Code for accessing WebService based on JQuery (accessible to Java [Xfire])_jquery

WBOY
WBOYOriginal
2016-05-16 18:16:041192browse

I took a closer look at several people's examples and found the problem. As we all know, WebService complies with the SOAP protocol. Why are the examples all passing parameters in JSON format? net WebService is compatible with JSON format, while Java's is a standard WebService and is not compatible with JSON. It seems that the net has harmed everyone. So I carefully understood the WSDL file and made an example. Only the key code is placed below.

Copy code 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 should not be used here
dataType:'xml',//Set to XML or not. Setting it to JSON format will make the return value NULL
success: function(xml) {
//Perform XML parsing on the result. 🎜>//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 satisfy the SOAP protocol.
function getPostData()
{
//According to WSDL analysis sayHelloWorld is the method name, parameters is the name of the incoming parameters
var postdata="";
postdata ="";
postdata ="";
postdata ="" $("#txtName").val() "";
postdata ="
";
postdata ="
";
return postdata;
}

Full example SVN address: http://theyounglearningmaterials.googlecode.com/svn/trunk/JavaWebServices/WebServiceTest/
All my future learning examples will be placed at http://theyounglearningmaterials.googlecode.com/svn/trunk/ for convenience Manage to prevent loss.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn