Reputation: 2563
I got this error:
Parsing error: Unexpected token, expected ,
I searched on web and I tried but nothing solved. Also I dont see any mistake here
constructor(props) {
super(props);
fetch('url', {
method: 'POST',
headers: new Headers({
Accept: 'application/json',
'Content-Type': 'application/json', // <-- Specifying the Content-Type
}),
body: JSON.stringify(collection) // <-- Post parameters
})
.then((response) => response.text())
.then(leaders => {
console.log(leaders);
}
} <---- here it gives error
Upvotes: 0
Views: 280
Reputation: 6742
fetch('url', {
method: 'POST',
headers: new Headers({
Accept: 'application/json',
'Content-Type': 'application/json', // <-- Specifying the Content-Type
}),
body: JSON.stringify(collection), // <-- Post parameters
})
.then(response => response.text())
.then((leaders) => {
console.log(leaders);
}); // << here's your issue ... missing `)`
SUGGESTION
Use async-await
syntax for more readaable and easy to debug async code
Upvotes: 1