JSFiddle - React, Tailwind, and code Playground
by lottikarotti
JavaScript
/**
* Simple XHR Object Factory
* min.js: http://goo.gl/D1pKSQ
*
* usage:
* var xhr = createXHRobj();
* xhr.open('GET', 'http://example.org/data', true);
* xhr.send();
*/
(function(global){
'use strict';
global.createXHRobj = (function(){
var i, factory=null, Xhr=global.XMLHttpRequest, AXo, activex = [
'MSXML2.XMLHTTP.3.0',
'MSXML2.XMLHTTP',
'Microsoft.XMLHTTP'
];
if(typeof Xhr === 'function'){
factory = function(){
return new Xhr();
};
} else{
AXo = global.ActiveXObject;
for(i=0; i<activex.length; i++){
try {
factory = new AXo(activex[i]);
factory = function(){
return new AXo(activex[i]);
};
break;
} catch(e){
factory = null;
}
}
}
if(!factory){
throw 'xhr not supported.';
}
return factory;
}()); // self-executing
}(window));