javascript 调用WebService

<script language="javascript">
HTTPRequest = function () {
 var xmlhttp=null;
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (_e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (_E) { }
 }
 if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
  try {
   xmlhttp = new XMLHttpRequest();
  } catch (e) {
   xmlhttp = false;
  }
 }
 return xmlhttp;
}

function Http_Request() {
  soaprequest = "<?xml version=/"1.0/" encoding=/"utf-8/"?>" + String.fromCharCode(10);
  soaprequest += "<soap:Envelope xmlns:xsi=/"http://www.w3.org/2001/XMLSchema-instance/" xmlns:xsd=/"http://www.w3.org/2001/XMLSchema/" xmlns:soap=/"http://schemas.xmlsoap.org/soap/envelope//">" + String.fromCharCode(10);
  soaprequest += "<soap:Body>" + String.fromCharCode(10);
  soaprequest += "<Add xmlns=/"http://liuhui//">" + String.fromCharCode(10);
  soaprequest += "<l>" + TxtL.value + "</l>" + String.fromCharCode(10);
  soaprequest += "<r>" + TxtR.value + "</r>" + String.fromCharCode(10);
  soaprequest += "</Add>" + String.fromCharCode(10);
  soaprequest += "</soap:Body>" + String.fromCharCode(10);
  soaprequest += "</soap:Envelope>" + String.fromCharCode(10);
 
 var http = new HTTPRequest();
 http.open("POST", "http://localhost/WebSite/WebService1/Service.asmx", false);
  http.setRequestHeader("Content-Type", "text/xml;charset=utf-8");
  http.setRequestHeader("Host","localhost"); 
  http.setRequestHeader("Content-Length",soaprequest.length);
  http.setRequestHeader("SOAPAction", "http://liuhui/Add");
 http.onreadystatechange = function (){ handleHttpResponse(http)};
 http.send(soaprequest);
}

function handleHttpResponse(http) {
 if (http.readyState == 4) {
  var result = http.responseText;  
  //alert(result);  
  RT.innerHTML = "<b>结果为: </b>" + result;
 }
}
</script>
<hr width="20%" align="left">
WEB服务<br>
左值<input type="text" id="TxtL" /><br>
右值<input type="text" id="TxtR" /><br>
<input type="button" οnclick="javascript:Http_Request();" value=" OK "/>
<hr width="20%" align="left">
<div id="RT"></div> 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值