javascript的一段代码,请指出错误,并给出解决办法

来源:百度知道 编辑:UC知道 时间:2024/06/15 14:26:00
<script type="text/javascript">
var oXmlHttp = new ActiveXObject("MSXML2.serverXMLHTTP.3.0");
oXmlHttp.open("GET","http://www.163.com", false);
oXmlHttp.send();

var result= oXmlHttp.responseText;
oXmlHttp.Close();
oXmlHttp = null;
document.write(result);
}

就是想获得163的页面

送你我自己写的AJAX类,用起来很方便的。

function Ajax(){
var obj = this;
this.Http = null;
this.getHttp = function(){
try{ obj.Http = new XMLHttpRequest();}
catch(e){ if(ActiveXObject)obj.Http = new ActiveXObject("Microsoft.XMLHTTP");}
}
this.getHttp();

this.parameters = [];
this.url = "";
this.asynchronous = true;
this.frontFun = function(){}
this.endFun = function(){}
this.returnFun = function(a){}
this.onError = function(msg){}
this.addParameter = function(a){
var prm = a.split("=");
obj.parameters.push(prm[0] + "=" + escape(prm[1]));
}

this.Http.onreadystatechange = function(){
if(obj.Http.readyState == 4){if(obj.Http.status == 200) obj.returnFun(obj.Http.responseText);else obj.onError("Ajax return error!");}
}

this.send = function(){
if(!obj.Http) {obj.H