需要一些帮助为 JSON API 编写搜索端点。
我无法正常工作的主要区域在 search.html 中。
JS 获取端点代码搜索.html:
<script>
fetchData();
function getData(data) {
fetch("https://uv056j.csb.app/data/custAPI.json", {
method: "GET",
body: JSON.stringify(data),
headers: {
"Content-type": "application/json; charset=UTF-8",
},
})
.then((response) => response.json())
.then((json) => console.log(json));
},
fetchData();
function postData(data) {
fetch("https://uv056j.csb.app/data/custAPI.json", {
method: "POST",
value: "q",
body: JSON.stringify(data),
headers: {
"Content-type": "application/json; charset=UTF-8",
},
})
.then((response) => response.json())
.then((json) => console.log(json));
}
</script>
不确定我的端点是否正确写入。我怎样才能使这项工作?
我期待看到搜索栏使用选择填充 json 数据,然后选择或将值传递给 search.html 页面。我一直没有成功。