您的位置:首页 > 理论基础 > 计算机网络

ajax 之XMLHttpRequest两种创建方法

2009-02-06 08:41 309 查看
/**//* 创建XMLHttpRequest的第一种方法
try{
searchReq = new ActiveXObject('Msxml2.XMLHTTP');
}
catch(e){
try{
searchReq = new ActiveXObject('Microsoft.XMLHTTP');
}
catch(e){
try{
searchReq = new XMLHttpRequest();
}
catch(e)
{}
}
}
*/
//创建XMLHttpRequest的第二种方法
function createReq(){
var httpReq;

if(window.XMLHttpRequest){
httpReq = new XMLHttpRequest();
if(httpReq.overrideMimeType){
httpReq.overrideMimeType('text/xml');
}
}
else if(window.ActiveXObject){
try{
httpReq = new ActiveXObject('Msxml2.XMLHTTP');
}
catch(e){
try{
httpReq = new ActiveXObject('Microsoft.XMLHTTP');
}
catch(e){
}
}
}
return httpReq;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: