最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Uncaught SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse - Stack Overflow

programmeradmin3浏览0评论

I'm trying to learn JavaScript and I keep getting the error "Uncaught SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse".

var ourRequest = new XMLHttpRequest();
ourRequest.open('GET', '.json');

ourRequest.onload = function(){
    var ourData  = JSON.parse(ourRequest.resoponseText);
    console.log(ourData[0]);
};
ourRequest.send();

I'm trying to learn JavaScript and I keep getting the error "Uncaught SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse".

var ourRequest = new XMLHttpRequest();
ourRequest.open('GET', 'https://learnwebcode.github.io/json-example/animals-1.json');

ourRequest.onload = function(){
    var ourData  = JSON.parse(ourRequest.resoponseText);
    console.log(ourData[0]);
};
ourRequest.send();
Share Improve this question asked Sep 4, 2017 at 20:00 Mssol94Mssol94 171 silver badge4 bronze badges 1
  • 2 it looks like you have a typo, i imagine it should be responseText. – Paul Fitzgerald Commented Sep 4, 2017 at 20:03
Add a ment  | 

2 Answers 2

Reset to default 6

You've simply misspelt resoponseText - It should be responseText. You get the error because JavaScript ends up calling JSON.parse("undefined").

You have a typo: you wrote ourRequest.resoponseText rather than ourRequest.responseText.

发布评论

评论列表(0)

  1. 暂无评论