JS调用WebService

时间:2023-03-09 17:36:55
JS调用WebService
<html>
<title>接口测试</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<body>
<script language="javascript">
function RequestByPost()
{
var KUNNR = document.getElementById('KUNNR').value;
var NAME1 = document.getElementById('KUNNR').value;
var TELF1 = document.getElementById('KUNNR').value;
var CALLNAME = document.getElementById('KUNNR').value;
var data; data = '<?xml version="1.0" encoding="utf-8"?>';
data = data + '<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/">';
data = data + '<soap:Body>';
data = data + '<CallInfo xmlns="http://10.100.110.33/Service">';
data = data + '<KUNNR>'+KUNNR+'</KUNNR>';
data = data + '<NAME1>'+NAME1+'</NAME1>';
data = data + '<TELF1>'+TELF1+'</TELF1>';
data = data + '<CALLNAME>'+CALLNAME+'</CALLNAME>';
data = data + '</CallInfo>';
data = data + '</soap:Body>';
data = data + '</soap:Envelope>'; //var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
var URL="http://10.100.110.33:8188/service.asmx";
xmlhttp.Open("POST",URL, false);
xmlhttp.SetRequestHeader ("Content-Type","text/xml; charset=gb2312");
xmlhttp.SetRequestHeader ("SOAPAction","http://10.100.110.33/Service/CallInfo");
xmlhttp.Send(data);
document.write( xmlhttp.responseText);
alert(data);
} // --></script>
<input id="KUNNR" type="text" value=""></br>
<input id="NAME1" type="text" value=""></br>
<input id="TELF1" type="text" value=""></br>
<input id="CALLNAME" type="text" value=""></br>
<input type="button" value="send" onclick="RequestByPost()">
</body>
</html>