Home > Mobile >  In React, I am getting this following error "Uncaught (in promise) TypeError: Failed to execute
In React, I am getting this following error "Uncaught (in promise) TypeError: Failed to execute

Time:01-27

Here is my code sample I want to add the new userInputData to the fakeJsonApi however I encounter the error **"Uncaught (in promise) TypeError: Failed to execute 'fetch' on 'Window': Invalid name" **

The data I fetched from - enter image description here

CodePudding user response:

The issue is with the way you are defining the headers for the fetch request.

headers: {
'Content-type ': 'application/json', 
'Accept': 'appliaction/json',
 body: JSON.stringify(dataItems)
}

There is an extra whitespace after "Content-type " that is causing the headers to be invalid. Remove the whitespace to fix the issue.

   headers: {
    'Content-type': 'application/json', 
    'Accept': 'appliaction/json',
     body: JSON.stringify(dataItems)
    }
  • Related