public
Created

  • Download Gist
gistfile1.txt
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 38 39 40 41 42
var xhr = (function() {
var XHR = function() {
var xmlhttp = false;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp = false;
}
}
this.xmlhttp = xmlhttp;
};
XHR.prototype.post = function(options) {
this.request.apply(this, ["POST", options]);
};
XHR.prototype.get = function(options) {
this.request.apply(this, ["GET", options]);
};
XHR.prototype.request = function(type, options) {
if (this.xmlhttp) {
var _xhr = this.xmlhttp;
_xhr.open(type, options.url, true);
_xhr.onreadystatechange = function() {
if (_xhr.readyState == 4) {
options.success.apply(this, [_xhr.responseText]);
}
// add failure callback
};
_xhr.send(null);
}
};
return new XHR();
})();

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.