API - CORS issue on React fetch

0 votes
29 views
added Mar 19 in API by lcjr First Warrant Officer (11,850 points)

Comment the header {} on your code:

const response = await fetch(YOUR_API_SRC, {
  method: 'POST',
  // headers: {
  //   // 'Content-Type': 'application/json',
  // },
  // body: JSON.stringify({ input: inputValue }),
  body: JSON.stringify({ "input": { "message": inputValue} }),
});

 

Why header {} causing issue? 

Frontend fetching dont need header {}, usually uses for server (and backend configurations) 

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...