24 lines
437 B
JavaScript
24 lines
437 B
JavaScript
function get(url) {
|
|
return new Promise(function (resolve, reject) {
|
|
var req = new XMLHttpRequest();
|
|
req.open('GET', url);
|
|
|
|
req.onload = function onload() {
|
|
if (req.status === 200) {
|
|
resolve(req.response);
|
|
} else {
|
|
reject(Error(req.statusText));
|
|
}
|
|
};
|
|
|
|
req.onerror = function onerror() {
|
|
reject(Error('Network Error'));
|
|
};
|
|
|
|
req.send();
|
|
});
|
|
}
|
|
function getJSON(url) {
|
|
return get(url).then(JSON.parse);
|
|
}
|