首页 > 代码库 > Js 调用 WebService 实例
Js 调用 WebService 实例
Html页面代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Js调用WebService</title> <script type="text/javascript"> function RequestWebService() { //这是我们在第一步中创建的Web服务的地址 var URL = "http://192.168.210.51:8012/Service.asmx"; var fun = "getAllData"; //在这处我们拼接 var data; data = ‘<?xml version="1.0" encoding="utf-8"?>‘; data = data + ‘<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">‘; data = data + ‘<soap12:Body>‘; data = data + ‘<‘ + fun + ‘ xmlns="http://tempuri.org/" >‘; data = data + ‘<view>V_Gis_Mid_WasteWaterYearData</view>‘; data = data + ‘<condition>EnterpriseCode = 520100000238</condition>‘; data = data + ‘</‘ + fun + ‘>‘; data = data + ‘</soap12:Body>‘; data = data + ‘</soap12:Envelope>‘; //创建异步对象 var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); xmlhttp.Open("POST", URL, false); xmlhttp.SetRequestHeader("Content-Type", "application/soap+xml"); xmlhttp.Send(data); document.getElementById("data").innerHTML = xmlhttp.responseText; } </script></head><body> <div> <input id="One" type="button" value="JsCallWebService" onclick="RequestWebService()" /> </div> <div id="data"> </div></body></html>
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。