XMLHttpRequest 对象是名为 AJAX 的 Web 应用程序架构的一项关键功能.
所有现代浏览器 (IE7+、Firefox、Chrome、Safari 以及 Opera) 都内建了 XMLHttpRequest 对象.但是, 老版本的 Internet Explorer (IE5 和 IE6)使用 ActiveX 对象.
function() {
var http, last_e;
if(!dojo.isIE || !dojo.config.ieForceActiveXXhr) {
// 如果 不是IE, 或者是 在IE下但是没有指定要用 ActiveXObject
// 去创建 XHR的情况下, 先尝试用 XMLHttpRequest() 去创建
try {
http = new XMLHttpRequest();
} catch(e) {
}
}
if(!http) {
// 如果用 new XMLHttpRequest() 创建不成功, 接着
// 用 new ActiveXObject() 去尝试
for(var i = 0; i < 3; ++i) {
// d._XMLHTTP_PROGIDS =
// ["Msxml2.XMLHTTP", "Microsoft.XMLHTTP", "Msxml2.XMLHTTP.4.0"]
var progid = d._XMLHTTP_PROGIDS[i];
try {
http = new ActiveXObject(progid);
} catch(e) {
last_e = e;
}
if(http) {
// Catch 正确的 PROGID, 下次创建XHR时, 不用再尝试
// 加快了速度
d._XMLHTTP_PROGIDS = [progid];
break;
}
}
}
if(!http) {
throw new Error("XMLHTTP not available: " + last_e);
}
return http;
}