Files
xiaozhi-esp32-server/manager/static/js/common.js
T

40 lines
1.0 KiB
JavaScript
Raw Normal View History

2025-02-15 16:17:08 +08:00
function post(api, bodyData, fn) {
2025-02-15 17:49:22 +08:00
let basePath = '';
2025-02-15 16:17:08 +08:00
let token = localStorage.getItem('token');
fetch(basePath + api, {
method: "POST",
headers: {
'Content-Type': 'application/json',
'Authorization': token,
},
body: bodyData==null ? null : JSON.stringify(bodyData)
})
.then(response => response.json())
.then(data => {
if(data.code === 401){
window.location = 'login.html';
return
}
fn(data);
});
}
function get(api, fn) {
let basePath = 'http://localhost:8001';
let token = localStorage.getItem('token');
fetch(basePath + api, {
method: "GET",
headers: {
'Content-Type': 'application/json',
'Authorization': token,
},
})
.then(response => response.json())
.then(data => {
if(data.code === 401){
window.location = 'login.html';
return
}
fn(data);
});
}