public
Last active

  • Download Gist
q-xhr.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 
var Q = require("q");
 
exports.read = function (path, timeout) {
var response = Q.defer();
var request = new XMLHttpRequest(); // ActiveX blah blah
request.open("GET", path, true);
request.onreadystatechange = function () {
if (request.readyState === 4) {
if (request.status === 200) {
response.resolve(request.responseText);
} else {
response.reject("HTTP " + request.status + " for " + path);
}
}
};
timeout && setTimeout(response.reject, timeout);
request.send('');
return response.promise;
};

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.