参考网上资料:
$(document).ready(function(){
$("#b").click(function(){
$.ajax({
contentType:"text/xml",
type:"POST",//访问WebService使用Post方式请求
url:"http://192.168.0.146:8085/HelloWorldService?wsdl",//调用WebService的地址和方法名称组合---WsURL/方法名
data:getPostData(),
dataType:"xml",
success:function(result){//回调函数,result,返回值
//alert(result);
alert($(result).find('return').text());
},
error:function(x,e){
alert('error:'+x.responseText);
},
complete:function(x){
//alert('complete:'x.responseText);
}
});
})
})
//定义满足SOAP协议的参数。
functiongetPostData()
{
//根据WSDL分析sayHelloWorld是方法名,parameters是传入参数名
varpostdata="<?xmlversion=\"1.0\"encoding=\"utf-8\"?>";
postdata+="<soap:Envelopexmlns: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><getGreetingsxmlns=\"http://tempuri.org/\">";
postdata+="<parameters>"+'中文'+"</parameters>";
postdata+="</getGreetings></soap:Body>";
postdata+="</soap:Envelope>";
returnpostdata;
}