不同浏览器创建XMLHttpRequest对象
1 function getXHR() { 2 if (XMLHttpRequest) { 3 return new XMLHttpRequest(); 4 } 5 else { 6 return new ActiveXObject("Microsoft.XMLHTTP"); 7 } 8 }
1 function getXHR() { 2 if (typeof XMLHttpRequest == "undefined") { 3 XMLHttpRequest = function() { 4 try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch (e) { } 5 try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch (e) { } 6 try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { } 7 return false; 8 } 9 } 10 return new XMLHttpRequest(); 11 }