1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
/** This is a list of XMLHttpRequest creation factory functions to try*/
XHRfactories = [
function() { return new XMLHttpRequest(); },
function() { return new ActiveXObject("Msxml2.XMLHTTP"); },
function() { return new ActiveXObject("Microsoft.XMLHTTP"); }
];
/** When we find a factory that works, store it here*/
XHRfactory = null;
function XHRnewRequest() {
if (XHRfactory !== null) {
return XHRfactory();
}
for(var i = 0; i < XHRfactories.length; i++) {
try {
var factory = XHRfactories[i];
var request = factory();
if (request !== null) {
XHRfactory = factory;
return request;
}
}
catch(e) {
continue;
}
}
// If we get here, none of the factory candidates succeeded,
// so throw an exception now and for all future calls.
XHRfactory = function() {
throw new Error("XMLHttpRequest not supported");
};
XHRfactory(); // Throw an error
} |
Partager