FacialRecognition-Demo/application/static/coms.js

59 lines
1.5 KiB
JavaScript
Raw Normal View History

2020-03-20 20:21:31 +00:00
function getJSON(url, callback, fallback) {
2020-03-19 16:52:30 +00:00
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'json';
xhr.onload = function () {
var status = xhr.status;
if (status < 400) {
callback(null, xhr.response);
} else {
2020-03-20 20:21:31 +00:00
fallback();
2020-03-19 16:52:30 +00:00
}
};
xhr.send();
};
2020-03-20 20:21:31 +00:00
function putJSON(url, data, callback, fallback) {
2020-03-19 16:52:30 +00:00
var xhr = new XMLHttpRequest();
xhr.open('PUT', url, true);
xhr.responseType = 'json';
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onload = function () {
var status = xhr.status;
if (status < 400) {
callback(null, xhr.response);
} else {
2020-03-20 20:21:31 +00:00
fallback();
2020-03-19 16:52:30 +00:00
}
};
xhr.send(data);
};
2020-03-20 20:21:31 +00:00
function postJSON(url, data, callback, fallback) {
2020-03-19 16:52:30 +00:00
var xhr = new XMLHttpRequest();
xhr.open('POST', url, true);
xhr.responseType = 'json';
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onload = function () {
var status = xhr.status;
if (status < 400) {
callback(null, xhr.response);
} else {
2020-03-20 20:21:31 +00:00
fallback();
2020-03-19 16:52:30 +00:00
}
};
xhr.send(data);
2020-05-11 17:24:50 +00:00
};
function deleteJSON(url, callback, fallback) {
var xhr = new XMLHttpRequest();
xhr.open('DELETE', url, false);
xhr.onload = function () {
var status = xhr.status;
if (status < 400) {
callback(null, xhr.response);
} else {
fallback();
}
};
xhr.send();
2020-03-19 16:52:30 +00:00
};