add js
This commit is contained in:
@ -0,0 +1,35 @@
|
|||||||
|
// 修改原有的数据获取方式
|
||||||
|
async function fetchSites() {
|
||||||
|
try {
|
||||||
|
const response = await fetch('/api/sites');
|
||||||
|
if (!response.ok) throw new Error('Network response was not ok');
|
||||||
|
return await response.json();
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching sites:', error);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改添加网站的函数
|
||||||
|
async function addSite(site) {
|
||||||
|
const response = await fetch('/api/add', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify(site)
|
||||||
|
});
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 修改删除网站的函数
|
||||||
|
async function deleteSite(id) {
|
||||||
|
const response = await fetch('/api/delete', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ id })
|
||||||
|
});
|
||||||
|
return await response.json();
|
||||||
|
}
|
Reference in New Issue
Block a user