Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View q-xhr.js
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;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.