File: /var/www/quadcode-site/src/utils/Ajax.js
let load = false;
export const Ajax = (method, url, body = null) => {
const _fetch = (url) => {
load = true;
return fetch(url, {
method: method,
headers: {
'X-Requested-With': 'XMLHttpRequest'
},
body: body
})
.then(result => {
load = false;
return result;
})
.catch(err => {
load = false;
throw err;
});
}
if (method === 'POST') {
return _fetch(url, 'POST', body);
}
if (method === 'GET') {
return _fetch(url);
}
}
export const loading = () => {
return load;
}