1
0
Fork 0

Optimized XHR factory

This commit is contained in:
Gregory Eremin 2015-03-27 20:31:36 +07:00
parent de7b9a7b80
commit f2f68fc1ee
1 changed files with 17 additions and 11 deletions

View File

@ -1,18 +1,24 @@
function getXHR(){ try {
var xhr; new ActiveXObject("Msxml2.XMLHTTP");
getXHR = function() {
return new ActiveXObject("Msxml2.XMLHTTP");
}
} catch (e) {
try { try {
xhr = new ActiveXObject("Msxml2.XMLHTTP"); new ActiveXObject("Microsoft.XMLHTTP");
getXHR = function() {
return new ActiveXObject("Microsoft.XMLHTTP");
}
} catch (e) { } catch (e) {
try { if (typeof XMLHttpRequest !== 'undefined') {
xhr = new ActiveXObject("Microsoft.XMLHTTP"); getXHR = function() {
} catch (e) { return new XMLHttpRequest();
xhr = false; }
} else {
alert("Something went really wrong!");
console.log("XHR is not available");
} }
} }
if (!xhr && typeof XMLHttpRequest !== 'undefined') {
xhr = new XMLHttpRequest();
}
return xhr;
} }
function getURL(url, params, callback) { function getURL(url, params, callback) {