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.
$(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.