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(); };¿Qué pasa con este código?
error :
No capturado (en promesa) TypeError: no se pudo ejecutar 'fetch' en 'Window': nombre no válido
Te has equivocado en esta linea
"content/type": "application/json""tipo de contenido": "aplicación/json"
Debería ser así,
fetch("https://enigmatic-eyrie-33917.herokuapp.com/product", { method: "POST", headers: { "content-type": "application/json", }, body: JSON.stringify(card), })documento oficial aquí
Espero que te aclares con esto.