'JSON Object values set to null when posting from NEXTJS to EXPRESS
I realised a form using NextJs and on the submit button click i would love to save the values to a MongoDb database , so i implemented a function
I am using EXPRESS to run my Backend for your information.
const validationForm = async (values)=>{
const result = await fetch("http://localhost:8000/inscription",{
mode:'no-cors' ,
method: 'post',
body: JSON.stringify(values),
headers : {
'Content-type':'application/json'
}
})
const body = await result.json()
console.log(body)
}
but in my database every field of the JSON Object is set to Null , now that is just part of the problem , the other part is that when i submit the form i get an error directly in the navigator :
Unhandled Runtime Error
SyntaxError: Unexpected end of input
const body = await result.json()
^
i have tried removing the await result.json() line of code and i dont get the error no more , but still the values of the JSON Object are set to Null. => values contains ( name,surname,password....etc)
NOTE: I am using the NO-CORS mode because otherwise i get blocked with the cors policy, so if anyone could help with that , it would be much appreciated.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
