2021-05-31 07:17:07 +00:00
|
|
|
function httpGetAsync(url, data, callback) {
|
2021-05-23 07:54:48 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-05-31 07:17:07 +00:00
|
|
|
function saveFile(url, filename, mimetype) {
|
|
|
|
const xmlHttp = new XMLHttpRequest();
|
|
|
|
xmlHttp.onreadystatechange = function () {
|
|
|
|
if (this.readyState === 4) {
|
|
|
|
if (xmlHttp.status === 200) {
|
|
|
|
let element = document.createElement('a');
|
|
|
|
element.setAttribute('href', 'data:' + mimetype + ',' + encodeURIComponent(xmlHttp.responseText));
|
|
|
|
element.setAttribute('download', filename);
|
|
|
|
|
|
|
|
element.style.display = 'none';
|
|
|
|
document.body.appendChild(element);
|
|
|
|
element.click();
|
|
|
|
document.body.removeChild(element);
|
|
|
|
} else {
|
|
|
|
create_error_view("Error " + xmlHttp.status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
xmlHttp.open("GET", url, true);
|
|
|
|
xmlHttp.setRequestHeader('Authorization', 'Basic ' + sessionStorage.getItem('authorization'));
|
|
|
|
xmlHttp.send(null);
|
|
|
|
}
|
|
|
|
|
2021-05-23 07:54:48 +00:00
|
|
|
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'));
|
2021-05-31 07:17:07 +00:00
|
|
|
xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
|
|
|
xmlHttp.send('content=' + btoa(data));
|
2021-05-23 07:54:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|