66 lines
2.1 KiB
JavaScript
66 lines
2.1 KiB
JavaScript
|
function httpGetAsync(url, data, callback) { // data includes auth
|
||
|
const xmlHttp = new XMLHttpRequest();
|
||
|
xmlHttp.onreadystatechange = function () {
|
||
|
if (this.readyState === 4) {
|
||
|
callback(xmlHttp.responseText, xmlHttp.status);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
xmlHttp.open("GET", url, true);
|
||
|
xmlHttp.setRequestHeader('Authorization', 'Basic ' + sessionStorage.getItem('authorization'));
|
||
|
xmlHttp.send(null);
|
||
|
}
|
||
|
|
||
|
function httpPostAsync(url, data, callback) {
|
||
|
const xmlHttp = new XMLHttpRequest();
|
||
|
xmlHttp.onreadystatechange = function () {
|
||
|
if (this.readyState === 4) {
|
||
|
callback(xmlHttp.responseText, xmlHttp.status);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
xmlHttp.open("POST", url, true);
|
||
|
xmlHttp.setRequestHeader('Authorization', 'Basic ' + sessionStorage.getItem('authorization'));
|
||
|
xmlHttp.setRequestHeader('Content-Type', 'application/json');
|
||
|
xmlHttp.send(JSON.stringify(data));
|
||
|
}
|
||
|
|
||
|
function httpDeleteAsync(url, data, callback) {
|
||
|
const xmlHttp = new XMLHttpRequest();
|
||
|
xmlHttp.onreadystatechange = function () {
|
||
|
if (this.readyState === 4) {
|
||
|
callback(xmlHttp.responseText, xmlHttp.status);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
xmlHttp.open("DELETE", url, true);
|
||
|
xmlHttp.setRequestHeader('Authorization', 'Basic ' + sessionStorage.getItem('authorization'));
|
||
|
xmlHttp.send();
|
||
|
}
|
||
|
|
||
|
function httpPutAsync(url, data, callback) {
|
||
|
const xmlHttp = new XMLHttpRequest();
|
||
|
xmlHttp.onreadystatechange = function () {
|
||
|
if (this.readyState === 4) {
|
||
|
callback(xmlHttp.responseText, xmlHttp.status);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
xmlHttp.open("PUT", url, true);
|
||
|
xmlHttp.setRequestHeader('Authorization', 'Basic ' + sessionStorage.getItem('authorization'));
|
||
|
xmlHttp.setRequestHeader('Content-Type', 'application/json');
|
||
|
xmlHttp.send(JSON.stringify(data));
|
||
|
}
|
||
|
|
||
|
function findGetParameter(parameterName) {
|
||
|
let result = null,
|
||
|
tmp = [];
|
||
|
location.search
|
||
|
.substr(1)
|
||
|
.split("&")
|
||
|
.forEach(function (item) {
|
||
|
tmp = item.split("=");
|
||
|
if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]);
|
||
|
});
|
||
|
return result;
|
||
|
}
|