rnn
rnn

Reputation: 2563

Parsing error: Unexpected token, expected ,

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

Answers (1)

Hend El-Sahli
Hend El-Sahli

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

Related Questions