不同浏览器创建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 }

 

posted @ 2013-06-17 12:00  David Huang  阅读(326)  评论(0编辑  收藏  举报