纯js调用webservice
2014-04-08 22:24
344 查看
先可以通过wsdl文档获取到请求体
<html> <head> <title>通过ajax调用WebService服务</title> <script> var xhr = new ActiveXObject("Microsoft.XMLHTTP"); function sendMsg(){ var name = document.getElementById('name').value; //服务的地址 var wsUrl = 'http://192.168.1.100:6789/hello'; //请求体 var soap = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0="http://ws.itcast.cn/" xm lns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' + ' <soapenv:Body> <q0:sayHello><arg0>'+name+'</arg0> </q0:sayHello> </soapenv:Body> </soapenv:Envelope>'; //打开连接 xhr.open('POST',wsUrl,true); //重新设置请求头 xhr.setRequestHeader("Content-Type","text/xml;charset=UTF-8"); //设置回调函数 xhr.onreadystatechange = _back; //发送请求 xhr.send(soap); } function _back(){ if(xhr.readyState == 4){ if(xhr.status == 200){ //alert('调用Webservice成功了'); var ret = xhr.responseXML; var msg = ret.getElementsByTagName('return')[0]; document.getElementById('showInfo').innerHTML = msg.text; //alert(msg.text); } } } </script> </head> <body> <input type="button" value="发送SOAP请求" onclick="sendMsg();"> <input type="text" id="name"> <div id="showInfo"> </div> </body> </html>
相关文章推荐
- JS调用webservice
- Js 调用 WebService心得总结(转)
- 使用js调用webservice的示例
- js调用ro的webservice
- Js 调用 WebService心得总结
- Js 调用 WebService心得总结
- 工作中用到的非常有用的JS调用WebService
- webservice跨域文件,好多年前的东西,远程调用,js服务器端使用,可以远程调用
- JS调用webservice服务
- js调用webservice
- JS调用WebService示例
- Js 调用 WebService心得总结
- NET-使用Js调用WebService
- js调用webService实现多态
- JS调用WEBSERVICE!
- Node.js 调用 restful webservice
- JS调用Webservice简单例子
- js调用WebService的几种方法
- Js 调用 WebService心得总结
- js调用WebService的几种方法