Mssol94
Mssol94

Reputation: 17

Uncaught SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse

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

Answers (2)

Kirk Larkin
Kirk Larkin

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

EKW
EKW

Reputation: 2113

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

Upvotes: 1

Related Questions