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

前端 未结 6 2330
情书的邮戳
情书的邮戳 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:25

    Normally it happens when you use arrow function for fetching data through API and in that you use 'this' keyword. So, arrow function not have its own 'this' So, we got error. This is not the main reason but it is one of them.

    fetch.addEventListener('load',()=> {
    
    const [delta] = JSON.parse(this.responseText);
    
    console.log(delta); 
    //Uncaught SyntaxError: Unexpected token U in JSON at position 0 at JSON.parse () 
    

提交回复
热议问题