mirror of
https://github.com/Alamantus/Lexiconga.git
synced 2025-05-19 08:31:25 +02:00
16 lines
496 B
JavaScript
16 lines
496 B
JavaScript
export function request (data = {}, success = () => {}, error = () => {}/* , fail = () => {} */) {
|
|
return fetch('./api/', {
|
|
method: 'POST', // or 'PUT'
|
|
body: JSON.stringify(data), // data can be `string` or {object}!
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
credentials: 'same-origin',
|
|
}).then(res => res.json())
|
|
.then(response => {
|
|
if (response.error) {
|
|
return error(response.data);
|
|
}
|
|
return success(response.data);
|
|
});
|
|
}
|