![](/img/trans.png)
[英]TypeError: Failed to execute 'fetch' on 'Window': Invalid name WITH Yelp API
[英]Uncaught (in promise) TypeError: Failed to execute 'fetch' on 'Window': Invalid name
const handleAddProduct = (e) => {
e.preventDefault()
const product_name = e.target.name.value;
const image = e.target.image.value;
const description = e.target.description.value;
const price = e.target.price.value;
const quantity = e.target.quantity.value;
const supplyar_name = e.target.supplier_name.value;
const card = {
product_name,
image,
description,
price,
quantity,
supplyar_name,
};
console.log(card);
fetch("https://enigmatic-eyrie-33917.herokuapp.com/product", {
method: "POST",
headers: {
"content/type": "application/json",
},
body: JSON.stringify(card),
})
.then((res) => res.json())
.then((data) => {
console.log(data);
});
e.target.reset();
};
這段代碼是怎么回事
錯誤:
未捕獲(承諾)類型錯誤:無法在“窗口”上執行“獲取”:名稱無效
你在這一行中犯了錯誤
"content/type": "application/json"
“內容類型”:“應用程序/json”
應該是這樣的
fetch("https://enigmatic-eyrie-33917.herokuapp.com/product", {
method: "POST",
headers: {
"content-type": "application/json",
},
body: JSON.stringify(card),
})
官方文檔在這里
我希望你清楚這一點。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.