日期:2014-05-16 浏览次数:20505 次
var SimpleXhrFactory = (function(){
var standard = {
createXhrObject: function(){
return new XMLHttpRequest();
}
};
var activeXNew = {
createXhrObject: function(){
return new ActiveXObject("Msxml2.XMLHTTP");
}
};
var activeXOld = {
createXhrObject: function(){
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
var testObject;
try {
testObject = standard.createXhrObject();
//testObject = null;it is mine?
return standard;
}
catch (e) {
try {
testObject = activeXNew.createXhrObject();
return activeXNew;
}
catch (e) {
try {
testObject = activeXOld.createXhrObject();
return activeXOld;
}
catch (e) {
throw new Error("No XHR Object found in this environment");
}
}
}
})();