js呼叫Web Service方式
阿新 • • 發佈:2018-10-31
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>qq線上測試</title>
- <script type="text/javascript">
- function getqq(){
- //建立XMLHttpRequest物件
- var xhr = new XMLHttpRequest();
- var url = "http://www.webxml.com.cn/webservices/qqOnlineWebService.asmx"
- //開啟連線
- xhr.open("post",url,true);
- //設定資料型別
- xhr.setRequestHeader("content-type","text/xml;charset
- //設定回撥函式
- xhr.onreadystatechange=function(){
- //判斷是否傳送成功和判斷服務端是否響應成功
- if(4 == xhr.readyState && 200 == xhr.status){
- alert(xhr.responseText);
- }
- }
- //組織SOAP協議資料
- var soapXML = "<?xml version="1.0" encoding="utf-8"?>"
- +"<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/">"
- +"<soap:Body>"
- +"<qqCheckOnline xmlns="http://WebXml.com.cn/">"
- +"<qqCode>"+document.getElementById("number").value+"</qqCode>"
- +"</qqCheckOnline>"
- +"</soap:Body>"
- +"</soap:Envelope>";
- alert(soapXML);
- //傳送資料
- xhr.send(soapXML);
- }
- </script>
- </head>
- <body>
- qq號查詢:<input type="text" id="number"/> <input type="button" value="查詢" onclick="javascript:getqq();"/>
- </body>
- </html>