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
2 Answers
Reset to default 6You'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条)