创建兼容于多浏览器支持的XMLHTTPRequest

  try{
        if( window.ActiveXObject ){
            for( var i = 5; i; i-- ){
                try{
                    if( i == 2 ){
xmlhttp_request = new ActiveXObject( "Microsoft.XMLHTTP" );   
                    }else{
xmlhttp_request = new ActiveXObject( "Msxml2.XMLHTTP." + i + ".0" );   
                    }

//xmlhttp_request.setRequestHeader方法必须在open方法之后被调用!!
//xmlhttp_request.setRequestHeader("Content-Type","text/xml");
//xmlhttp_request.setRequestHeader("Content-Type","gb2312");
break;}
                catch(e){                       
                    xmlhttp_request = false;
                }
            }
        }else if( window.XMLHttpRequest ){
            xmlhttp_request = new XMLHttpRequest();
            if (xmlhttp_request.overrideMimeType) {
                xmlhttp_request.overrideMimeType(''text/xml'');
            }
        }
    }catch(e){
        xmlhttp_request = false;
    }
文章出处:飞诺网(www.firnow.com):http://dev.firnow.com/course/1_web/webjs/2008515/116676.html

你可能感兴趣的:(XMLhttpREquest)