Uncaught SyntaxError: Unexpected token u in JSON at position 0

前端 未结 7 1431
[愿得一人]
[愿得一人] 2020-12-03 00:11

Only at the checkout and on individual product pages I am getting the following error in the console log:

VM35594:1 Uncaught SyntaxError: Unexpected token u          


        
7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 01:08

    I had this issue for 2 days, let me show you how I fixed it.

    This was how the code looked when I was getting the error:

    request.onload = function() {
        // This is where we begin accessing the Json
        let data = JSON.parse(this.response);
        console.log(data)
    }
    

    This is what I changed to get the result I wanted:

    request.onload = function() {
        // This is where we begin accessing the Json
        let data = JSON.parse(this.responseText);
        console.log(data)
    }
    

    So all I really did was change this.response to this.responseText.

提交回复
热议问题