ajax调用webservice
<html> <head> <title>通过ajax来调用webservice</title> <script type="text/javascript"> var xmlHttp = false; function sendMsg() { try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e2) { xmlHttp = false; } } if (!xmlHttp && typeof XMLHttpRequest != 'undefined') { xmlHttp = new XMLHttpRequest(); } alert("pass"); //服务的地址 var name = document.getElementById("name").value; alert(name); var wsUrl ="http://192.168.1.192:6789/hello"; //请求体 var soap ='<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0="http://webservice.powerjunior.org/" 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>'; //打开链接 xmlHttp.open('POST',wsUrl,true); //重新设置请求头 xmlHttp.setRequestHeader("Content-Type","text/xml;charset=UTF-8"); //设置回调函数 xmlHttp.onreadystatechange=_back; //发送请求 xmlHttp.send(soap); } //回调函数 function _back() { if(xmlHttp.readyState == 4) { if(xmlHttp.status == 200) { alert('调用webservice成功!'); var ret = xmlHttp.responseXML; var msg = ret.getElementsByTagName("return")[0]; document.getElementById("showInfo").innerHTML = msg.text; } } } </script> </head> <body> <input type ="button" onclick="sendMsg();" value="调用webservice"> <input type="text" id="name" /> <div id="showInfo"></div> </body> </html>
相关推荐
kentrl 2020-11-10
结束数据方法的参数,该如何定义?-- 集合为自定义实体类中的结合属性,有几个实体类,改变下标就行了。<input id="add" type="button" value="新增visitor&quo
ajaxyan 2020-11-09
zndy0 2020-11-03
学留痕 2020-09-20
Richardxx 2020-11-09
learningever 2020-09-19
chongxiaocheng 2020-08-16
ajaxhe 2020-08-16
lyqdanang 2020-08-16
curiousL 2020-08-03
TONIYH 2020-07-22
时光如瑾雨微凉 2020-07-19
83510998 2020-07-18
坚持着执着 2020-07-16
jiaguoquan00 2020-07-07
李永毅 2020-07-05
坚持着执着 2020-07-05