Uncaught SyntaxError: Unexpected token U in JSON at position 0 at JSON.parse () at Response.Body.json

前端 未结 6 2313
情书的邮戳
情书的邮戳 2021-02-15 14:16

I am working on an angular2 project. I am stuck with these errors. The error occured when I tried to send the JSON objects to the backend. It may be due the parsing of JSON obje

6条回答
  •  醉梦人生
    2021-02-15 14:41

    return this.http.post('http://localhost:3000/api/users', JSON.stringify(newreg),{headers: headers})
                .map(res=> res.json());
    

    The backend API at http://localhost:3000/api/users has a return type that is not JSON, in your case String beginning with the letter 'U'. Make sure the back end returns json data by using res.json("Your text here"); This is because your map function .map(res=> res.json()); is expecting a json response

提交回复
热议问题