I’m trying to send a new product data to my server and i get this err
Uncaught (in promise) SyntaxError: Unexpected end of JSON input
while the object that i’ve entered in JSON is not empty
const newProductsInfos = {
title: newProductTitle,
price: newProductPrice,
count: newProductCount,
img: newProductImg,
popularity: newProductPopularity,
sale: newProductSale,
colors: newProductColors
}
const addNewProduct = (event) => {
event.preventDefault();
fetch(`http://localhost:8000/api/products`, {
method: "POST",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(newProductsInfos)})
.then(res => res.json()).then(resullt=>{
console.log(resullt)
})
};
i have logged the response of json and its
Response {type: ‘cors’, url: ‘http://localhost:8000/api/products’, redirected: false, status: 200, ok: true, …} body : ReadableStream bodyUsed : false headers : Headers {} ok : true redirected : false status : 200 statusText : “OK” type : “cors” url : “http://localhost:8000/api/products” [[Prototype]] : Response
Mohammad Askari is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.