使用表单我将钱包信息添加到 JSON 服务器。当我逐步执行代码时,我可以看到我在调试器中输入的数据,但它以下面的错误结尾。我不知道为什么,如果它获取数据,我会收到 404“找不到文件”。我将钱包数据从 Json 服务器加载到页面,所以我新建了文件。
JSON:
{
"purseData": [
{
"id": 1,
"brand": "Jimmy Choo",
"style": "Bucket",
"color": "pink",
"size": "Extra Large",
"img": "https://media.jimmychoo.com/image/upload/q_auto:best,f_auto,dpr_2.0,w_900,h_900,c_fit/USPROD_PRODUCT/images/original/BONBONBUCKETSHUT_112562_FRONT_vg04.jpg",
"desc": "undefined",
"condition": "fair",
"price": "500"
},
{
"id": 2,
"brand": "Coach",
"style": "Lori Shoulder Bag",
"color": "Brass/Canyon Multi",
"size": "Medium",
"img": "https://encrypted-tbn1.gstatic.com/shopping?q=tbn:ANd9GcRvWaKEder8QK6uE_vCxZUbnB9wYzTiC0SK335iHYBsFwY5GSObnQdL66UbTLKs2wXPssbpaxA6u7GiCBeAXS4ilqrl0LtoecOv9eNvpdNwPLFo5nlgqicS1WDio9oKeB0mQg&usqp=CAc",
"desc": "undefined",
"condition": "new",
"price": "1000"
},
{
"brand": "Celine",
"style": "Ava Bag in Smooth Calfskin",
"color": "Tan",
"size": "Medium",
"img": "https://encrypted-tbn2.gstatic.com/shopping?q=tbn:ANd9GcQXBzeij04RjU_VxK1_ousQyBlL9K32I5yl6dfyI4_ioxAmWEWGYVEb5VLaABL91r6nyWjq2Q_tLAsS71iY9bffma7dRRfp_zhvy0D9Bs80qvaQwBJiiRgGguJDLj_LmEA-vQ&usqp=CAc",
"condition": "new",
"price": 2300,
"comments": "9 X 5 X 2 IN (23 X 13.5 X 6 CM),TRIOMPHE CANVAS, TRIMMINGS IN CALFSKIN,TEXTILE LINING,GOLD FINISHING,SHOULDER AND HAND CARRY,ZIPPED CLOSURE,ONE INNER FLAT POCKET,ADJUSTABLE STRAP WITH A MINIMUM DROP 8 IN (22 CM) AND MAXIMUM DROP 9 IN (23 CM),REFERENCE : 193952BZJ.04LU",
"seller": "Guy George",
"id": 3
}
]
}
// This adds new cards to the server.
function addPurseCard(purseObj) {
console.log("this is purse Object", purseObj)
fetch("http://localhost:3000/purseData/purseObj", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
},
body: JSON.stringify(purseObj)
})
.then(res => {
if (res.ok) { console.log("POST request successful!!!") }
else { console.log("POST request unsuccessful") }
return res
})
.then(res => res.json())
.then(newPurseObj => console.log(newPurseObj))
.then(newPurseObj => createPurseCard(newPurseObj))
.catch((error) => console.log(error))
}
这是 console.log 的输出。它显示了我试图添加到服务器的数据:
下面是我得到的错误:
我尝试单步执行调试器,我可以看到数据在移动,但它以 Post 请求错误结束。