JS创建Ajax的XMLHttpRequest对象的通用方法
1 function createXMLHttpRequest() { 2 var request = false; 3 if(window.XMLHttpRequest) { 4 request = new XMLHttpRequest(); 5 if(request.overrideMimeType) { 6 request.overrideMimeType('text/xml'); 7 } 8 } else if(window.ActiveXObject) { 9 var versions = ['Microsoft.XMLHTTP', 'MSXML.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.7.0', 'Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP']; 10 for(var i=0; i<versions.length; i++) { 11 try { 12 request = new ActiveXObject(versions[i]); 13 if(request) { 14 return request; 15 } 16 } catch(e) {} 17 } 18 } 19 return request; 20 }