var url = "b.aspx";
var param = "a=1&b=2";
var ret = GetRemoteText(url, param, 'post');
// 这个ret就是b.aspx返回的内容,使用吧
// 创建XmlHttp对象
function CreateXmlHttp() {
if (window.XMLHttpRequest)
return new XMLHttpRequest();
else {
var ver = ["MSXML2.XmlHttp.6.0", "MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0",
"MSXML2.XMLHttp.3.0","MSXML2.XMLHttp","Microsoft.XMLHttp"];
for (var i = 0; i < ver.length; i++)
try {
var XmlHttp = new ActiveXObject(ver[i]);
return XmlHttp;
}
catch (oError) {}
}
return false;
}
// 访问
function GetRemoteText(url,param,method){
if(method && method.toLowerCase() == 'post')
method = 'POST';
else{
method = 'GET';
}
var xml = CreateXmlHttp();
xml.open(method, url, false);
if(method == 'POST')
xml.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xml.send(param);
if(xml.readyState == 4 && xml.status == 200)
return xml.responseText;
else
return null;
}
|