I can’t find the problem with the fetch but it doesn’t work. Maybe the problem is with the backend?
No error codes, it’s just doesn’t show anything.
async function newData(e:FormEvent){
e.preventDefault();
const data={
data1,
data2,
data3,
data4
}
try{
const response=await fetch('http://localhost:3000/data',{
method:'POST',
body:JSON.stringify(data),
headers:{
'Content-type':'application/json',
'Accept':'application/json'
}
});
if(response.ok){
await loadData();
setData1('')
setData2('')
setData3('')
setData4(0)
setErrormessage('')
} else{
const errorObj=await response.json();
setErrormessage(errorObj.errors.message);
}
} catch(ex){
setErrormessage(ex.message);
}
}
New contributor
Winetou001 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.