Reputation: 17
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();
Upvotes: 0
Views: 2935
Reputation: 93053
You've simply misspelt resoponseText
- It should be responseText
. You get the error because JavaScript ends up calling JSON.parse("undefined")
.
Upvotes: 6
Reputation: 2113
You have a typo: you wrote ourRequest.resoponseText
rather than ourRequest.responseText
.
Upvotes: 1