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

I'm trying to learn JavaScript and I keep getting the error "Uncaught SyntaxError: Unexpected

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745595216a4635071.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信