1
0
Fork 0
mirror of https://github.com/Alamantus/Lexiconga.git synced 2025-11-21 02:11:57 +01:00
Lexiconga/src/js/account/helpers.js

21 lines
607 B
JavaScript
Raw Normal View History

2019-05-13 14:02:10 -06:00
export function request (data = {}, success = () => {}, error = () => {}, fail = () => {}) {
fetch('./account/', {
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 => {
console.log('Success:', JSON.stringify(response));
if (response.error) {
error(response);
}
success(response);
})
.catch(err => {
console.error('Request Error:', err);
fail(err);
});
}