esxlib/web/static/app/app.js

73 lines
1.7 KiB
JavaScript

let App = {};
App.Debug_NoRefesh = false;
App.GetObject = function(path, updateFunc) {
fetch(path , {
method: "GET",
}).then(response => {
// console.log("Response:", response.text());
return response.json()
}).then(data => {
console.log("Request OK:", data);
updateFunc(data)
}).catch(error => {
console.log("Request ERROR:", error);
updateFunc({})
})
}
App.PostObject = function (path, data, updateFunc) {
fetch(path , {
method: "POST",
body: data,
}).then(response => {
return response.json()
}).then(data => {
console.log("Request OK:", data);
updateFunc(data)
}).catch(error => {
console.log("Request ERROR:", error);
})
}
App.PostObjectCheckError = function (path, data, onSuccess, onError) {
fetch(path , {
method: "POST",
body: data,
}).then(response => {
if ( response.status !== 200 ){
console.log("REQUEST ERR: ", response.status, data);
throw new Error(response.statusText)
}
return response.json()
}).then(data => {
console.log("REQUEST OK:", data);
onSuccess(data)
return data
}).catch(error => {
console.log("REQUEST ERROR:", error);
onError(error)
})
}
App.PostObjectEx = function (path, data, callback) {
fetch(path , {
method: "POST",
body: data,
}).then(response => {
return response.json()
}).then(data => {
console.log("Request OK:", data);
callback("")
}).catch(error => {
console.log("Request ERROR:", error);
callback(error)
})
}