/*分支技术*/
/* SimpleXhrFactory singleton */
var SimpleXhrFactory = (function() {
//The three branches.
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');
}
}
// To assign the branch, try each method; return whatever doesn't fail.
var testObject;
try {
testObject = standard.createXhrObject();
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.');
}
}
}
})();
如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛