<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>