I am using fetch to simply get data from a dummy api endpoint, but I get an unexpected end of input error when I add in the configs in the fetch
function.
This works just fine and console logs an array of 200 items
componentDidMount() {
let url = 'https://jsonplaceholder.typicode.com/todos';
let config = {
method: "GET",
mode: "no-cors",
headers: {
"access-control-allow-origin" : "*",
"Content-type": "application/json; charset=UTF-8",
"access-control-allow-headers": "content-type"
}
};
fetch(url)
.then(res => res.json())
.then(data => this.setState({ data, }))
}
But when I add in the configs as a parameter, it shows and error.
componentDidMount() {
let url = 'https://jsonplaceholder.typicode.com/todos';
let config = {
method: "GET",
mode: "no-cors",
headers: {
"access-control-allow-origin" : "*",
"Content-type": "application/json; charset=UTF-8",
"access-control-allow-headers": "content-type"
}
};
fetch(url, config) // This is where the error occurs
.then(res => res.json())
.then(data => this.setState({ data, }))
}
Error:
Dashboard.jsx:35 Uncaught (in promise) SyntaxError: Unexpected end of input
at Dashboard.jsx:35
and
Cross-Origin Read Blocking (CORB) blocked cross-origin response https://jsonplaceholder.typicode.com/todos with MIME type application/json.