admin管理员组文章数量:1026989
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
.
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
.
本文标签: javascriptUncaught SyntaxError Unexpected token u in JSON at position 0 at JSONparseStack Overflow
版权声明:本文标题:javascript - Uncaught SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745595215a2158126.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论