ajax请求webservice

前端之家收集整理的这篇文章主要介绍了ajax请求webservice前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<scripttype="text/javascript">

functionreqWebService(){

varname=document.getElementById("name").value;
//获取XMLHttpRequest
varrequest=GetXmlHttpObject();
//设置回调函数
request.onreadystatechange=function(){
if(request.readyState==4&&request.status==200)
{
varresult=request.responseXML;
alert(result);
varreturnEle=result.getElementsByTagName("return")[0];
varvalue=returnEle.firstChild.data;
alert(value);
}
}

//打开连接
request.open("POST","http://localhost:8090/sayhello");
//设置请求头
request.setRequestHeader("Content-type","application/x-www-form-urlencoded");
request.send('<soap:Envelopexmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Header><atguigu><name>yuanhai</name><password>123456</password></atguigu></soap:Header><soap:Body><sayHelloxmlns="http://server/"><arg0>'+name+'</arg0></sayHello></soap:Body></soap:Envelope>');


}



functionGetXmlHttpObject()
{
varxmlHttp=null;
try
{
//Firefox,Opera8.0+,Safari
xmlHttp=newXMLHttpRequest();
}
catch(e)
{
//InternetExplorer
try
{
xmlHttp=newActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
xmlHttp=newActiveXObject("Microsoft.XMLHTTP");
}
}
returnxmlHttp;
}
</script>
</head>
<body>
用户名:<inputid="name"name="username"value=""/>
<buttononclick="reqWebService()">Ajax请求webservice</button>
</body>
</html>
原文链接:https://www.f2er.com/ajax/162707.html

猜你在找的Ajax相关文章