利用XMLHTTP跨域访问

ChenReal

下面这个函数就是利用XMLHttp组件,获得远程服务端的HTTP代码的例子。

function getweb(url){
	var oXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	oXmlHttp.open("GET",url, false);
	oXmlHttp.send();
	var oStream = new ActiveXObject("ADODB.Stream");
	if(oStream == null){
		alert("您的机器不支持ADODB.Stream.");
	}
	else
	{
	   oStream.Type=1;
	   oStream.Mode=3;
	   oStream.Open() ;
	   oStream.Write(oXmlHttp.responseBody);
	   oStream.Position= 0;
	   oStream.Type= 2;
	   oStream.Charset="gb2312";
	   var result= oStream.ReadText();
	   oStream.Close();
	   oStream = null;           
	   return result;
	 }
 }