diff --git a/frontend/script.js b/frontend/script.js index e69de29..2614ba2 100644 --- a/frontend/script.js +++ b/frontend/script.js @@ -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(); +} \ No newline at end of file