Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript AJAX Basics Programming AJAX Parsing JSON Data

Maciej Wielgosz
Maciej Wielgosz
9,103 Points

The console does not show the same as in the video

This is my code in widget.js:

var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
 if(xhr.readyState === 4) {
   console.log(xhr.responseText);
 }
};
xhr.open('GET', '../data/employees.json');
xhr.send();

and html fragment (in index.html), in the same place as in the video:

  <script scr="js/widget.js"></script>

The path given in JS for employees.json required adding "../" because otherwise the console showed a 404 error, and sometimes it did not show anything. After correcting the path, the console (google chrome) does not show JSON content, and I can only see something like this:

Fetch finished loading: GET "chrome-extension://gomekmidlodglbbmalcneegieacbdmki/locales/Locale-pl.json".
fetchTranslation        @ contentInject.js:12099
getTranslations         @ contentInject.js:12088
registerI18nLocales  @ contentInject.js:12103
init                 @ contentInject.js:12075
create                 @ contentInject.js:12069
(anonymous)             @ contentInject.js:23304
9526                     @ contentInject.js:23308
o                     @ contentInject.js:23333
(anonymous)            @ contentInject.js:23354
(anonymous)            @ contentInject.js:23355

Fetch finished loading: GET "https://s-install.avcdn.net/aos/assets/prod/translations/Locale-en.json".
fetchTranslation        @ contentInject.js:12099
getTranslations         @ contentInject.js:12088
registerI18nLocales   @ contentInject.js:12103
init                 @ contentInject.js:12075
create                 @ contentInject.js:12069
(anonymous)            @ contentInject.js:23304
9526                   @ contentInject.js:23308
o                   @ contentInject.js:23333
(anonymous)            @ contentInject.js:23354
(anonymous)            @ contentInject.js:23355

Fetch finished loading: GET "https://s-install.avcdn.net/aos/assets/prod/translations/Locale-pl.json".
fetchTranslation         @ contentInject.js:12099
getTranslations          @ contentInject.js:12088
registerI18nLocales    @ contentInject.js:12103
init                  @ contentInject.js:12075
create                  @ contentInject.js:12069
(anonymous)            @ contentInject.js:23304
9526                   @ contentInject.js:23308
o                   @ contentInject.js:23333
(anonymous)         @ contentInject.js:23354
(anonymous)          @ contentInject.js:23355

Where am I making a mistake? Why the console does not show JSON content?

2 Answers

You have a typo.

<script scr="js/widget.js"></script>

scr should be src.

Maciej Wielgosz
Maciej Wielgosz
9,103 Points

Thanks :) I feel a bit like a fool ... :)