微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ajax调用webservice

<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.1:8080/hello';
//请求体

var soap = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0="http://ws.itcast.cn/"

xmlns: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="ajax调用WebService服务" onclick="sendMsg();"> <input type="text" id="name"> <div id="showInfo"> </div> </body> </html>

原文地址:https://www.jb51.cc/ajax/163691.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐