ajax調用webservice服務

來源:互聯網
上載者:User

標籤:style   class   blog   code   java   http   

ajax調用是 html方向調用的, 而sqlconnection是 java代碼調用的,本質差不多

 1 <html> 2     <head> 3         <title>通過ajax調用webservice服務</title> 4         <script> 5             var xhr; 6             function sendAjaxWS(){ 7                 xhr = new ActiveXObject("Microsoft.XMLHTTP"); 8                 //指定ws的請求地址 9                 var wsUrl = "http://192.168.1.108:5678/hello";10                 //手動構造請求體11                 var requestBody = ‘<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" ‘ + 12                                     ‘ xmlns:q0="http://service.itcast.cn/" xmlns:xsd="http://www.w3.org/2001/XMLSchema "‘+13                                     ‘ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">‘+14                                     ‘<soapenv:Body><q0:sayHello><arg0>‘+document.getElementById("msg").value+‘</arg0> <arg1>10</arg1> </q0:sayHello></soapenv:Body></soapenv:Envelope>‘;15                 //開啟串連16                 xhr.open("POST",wsUrl,true);17                 //重新佈建要求頭18                 xhr.setRequestHeader("content-type","text/xml;charset=utf8");19                 //設定回呼函數20                 xhr.onreadystatechange = _back;21                 //發送請求22                 xhr.send(requestBody);23             }24 25             //定義回呼函數26             function _back(){27                 if(xhr.readyState == 4){28                     if(xhr.status == 200){29                         var ret = xhr.responseXML;30                         //解析xml31                         var eles = ret.getElementsByTagName("return")[0];32                         alert(eles.text);33                     }34                 }35             }36         </script>37     </head>38     <body>39         <input type="text" id="msg" />40         <input type="button" onclick="sendAjaxWS();" value="通過ajax調用webservice服務"/>41     </body>42 </html>

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.