js调用Web Service方式

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Kellogg_and_Nina/article/details/78280704
  1. <!doctype html>  
  2. <html lang="en">  
  3.  <head>  
  4.   <meta charset="UTF-8">  
  5.   <title>qq在线测试</title>  
  6.   <script type="text/javascript">  
  7.     function getqq(){  
  8.         //创建XMLHttpRequest对象  
  9.         var xhr = new XMLHttpRequest(); 
  10.         var url = "http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx"
  11.         //打开连接  
  12.         xhr.open("post",url,true);  
  13.         //设置数据类型  
  14.         xhr.setRequestHeader("content-type","text/xml;charset=utf-8");  
  15.         //设置回调函数  
  16.         xhr.onreadystatechange=function(){  
  17.             //判断是否发送成功和判断服务端是否响应成功  
  18.             if(4 == xhr.readyState && 200 == xhr.status){  
  19.                 alert(xhr.responseText);  
  20.             }  
  21.         }  
  22.         //组织SOAP协议数据  
  23.         var soapXML = "<?xml version="1.0" encoding="utf-8"?>"  
  24.         +"<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/">"  
  25.             +"<soap:Body>"  
  26.             +"<qqCheckOnline xmlns="http://WebXml.com.cn/">"  
  27.                 +"<qqCode>"+document.getElementById("number").value+"</qqCode>"
  28.             +"</qqCheckOnline>"  
  29.           +"</soap:Body>"  
  30.         +"</soap:Envelope>";  
  31.         alert(soapXML);  
  32.         //发送数据  
  33.         xhr.send(soapXML);  
  34.     }  
  35.   </script>  
  36.  </head>  
  37.  <body>  
  38.   qq号查询:<input type="text" id="number"/> <input type="button" value="查询" onclick="javascript:getqq();"/>  
  39.  </body>  
  40. </html> 

猜你喜欢

转载自blog.csdn.net/Kellogg_and_Nina/article/details/78280704
今日推荐