帮你改一个能运行的版本,但是具体的业务和功能我就不得而知了。
注意到你尝试创建非IE浏览器的 XMLHttpRequest 对象,可是buildSoap方法使用了Microsoft.XMLDOM对象已经注定了这个程序不能在非IE浏览器上运行了,写了也是白写,但是还是给你保留了。
<HTML>
<HEAD>
<TITLE> SOAP test by emu </TITLE>
<META NAME="Author" CONTENT="emu">
</HEAD>
<script language="javascript" type="text/javascript">
function startTest(){
var ob= new A();
ob.createRequest();
}
function A(){ }
A.prototype.buildSoap = function(){
//创建一个soap,命名为this.soap
var xmlString = "<SOAP:Envelope xmlns:SOAP=\"
http://schemas.xmlsoap.org/soap/envelope/\">"+
"<SOAP:Header/>"+
"<SOAP:Body>"+
"<Authenticate>"+
"<username></username>"+
"<password></password>"+
"</Authenticate>"+
"</SOAP:Body>"+
"</SOAP:Envelope>";
this.soap = new ActiveXObject("Microsoft.XMLDOM");
this.soap.async = false;
this.soap.loadXML(xmlString);
this.soap.selectSingleNode(".//username").text = "administrator";
this.soap.selectSingleNode(".//password").text = "123456";
}
A.prototype.createRequest = function(){
var r;
try {r=new XMLHttpRequest();}catch(e){}
if(!r) try {r=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){}
if(!r) try {r=new ActiveXObject("Microsoft.XMLHTTP");}catch(e){}
if (!r) {
alert("Error initializing XMLHttpRequest!");
return;
}
var url="
http://www.blogjava.net";
r.open("POST",url,true);
r.onreadystatechange= function(){
if(r.readyState==4&&r.status==200)
alert("服务完成");
};
this.buildSoap();
r.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded");
r.setRequestHeader("If-Modified-Since","0");
r.send(this.soap.xml);
}
</script>
<body onload="startTest()">
</body>
</HTML>