网络编程
位置:首页>> 网络编程>> JavaScript>> javascript一个无懈可击的实例化XMLHttpRequest的方法

javascript一个无懈可击的实例化XMLHttpRequest的方法

  发布时间:2024-04-16 09:49:19 

标签:XMLHttpRequest

function getHTTPRequest()
{
var xhr = false;
if (window.XMLHttpRequest)
xhr = new XMLHttpRequest(); //IE除外的浏览器
else if (window.ActiveXObject)
{
try
{
xhr = new ActiveXObject("Msxm12.XMLHTTP");//最新版的ActiveX对象
}
catch(e)
{
try
{
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
xhr = false;
}
}
}
}


接下来是一个应用的实例:


//完整的GET请求
var request = getHTTPRequest();
if(request)
{
request.onreadystatechange = dosomething;
request.open("GET","file.doc",true);
request.send(null);
}
0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com