wifictld-analyzer/webroot/js/utils.js

24 lines
437 B
JavaScript
Raw Normal View History

2019-03-08 17:09:01 +01:00
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);
}