12,162
社区成员
发帖
与我相关
我的任务
分享
<script type="text/javascript">
var xmlHttp=null;
function createXMLHttpRequest()
{
if(xmlHttp == null){
if(window.XMLHttpRequest) {
//Mozilla 浏览器
xmlHttp = new XMLHttpRequest();
}else if(window.ActiveXObject) {
// IE浏览器
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
}
}
}
}
}
function openAjax()
{
if( xmlHttp == null)
{
createXMLHttpRequest();
if( xmlHttp == null)
{
//alert('出错');
return ;
}
}
var strPostSoap = "";
strPostSoap += "<?xml version='1.0' encoding='utf-8'?>";
strPostSoap += "<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/'>";
strPostSoap += " <soap:Body>";
strPostSoap += " <HelloWorld xmlns='http://tempuri.org/'>";
strPostSoap += " <name>123</name>";// 参数值
strPostSoap += " </HelloWorld>";
strPostSoap += " </soap:Body>";
strPostSoap += "</soap:Envelope>";
xmlHttp.onreadystatechange=xmlHttpChange;
xmlHttp.open("post","http://localhost/webservice1/service1.asmx",true);
xmlHttp.setRequestHeader("Content-Type", "text/xml");
xmlHttp.setRequestHeader("Host", "localhost");
xmlHttp.setRequestHeader("content-length",strPostSoap.length);
xmlHttp.setRequestHeader("SOAPAction", "http://tempuri.org/HelloWorld");
//发送SOAP请求
xmlHttp.send(strPostSoap);
}
function xmlHttpChange()
{
if(xmlHttp.readyState==4)
{
if(xmlHttp.status==200)
{
alert(xmlHttp.responseText);
}
}
}
</script>