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 trialGreg McDonald
7,255 PointsThe browser does not recognise the JavaScript source in the index
I have the source in my indext.html file, however nothing is being logged to the console, not even a simple 'Hi' log.
<html> <head> <meta charset="utf-8"> <title>AJAX Office Status Widget</title> <link href='http://fonts.googleapis.com/css?family=Varela+Round' rel='stylesheet' type='text/css'> <link rel="stylesheet" href="css/main.css"> <script src="js/widget.js"></script> </head>
var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { if (xhr.readyState === 4) { console.log(xhr.responseText); } } xhr.open('GET', 'data/employees.json'); xhr.send();
console.log("Hi");
3 Answers
benyoungblood
10,062 PointsYou are really close. You just forgot to specify the directory properly in xhr.open();
. Your file path needs ../
added prior to /data/employees.json'
The correction in your javascript file is below. It is working just fine now!
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
console.log(xhr.responseText);
}
}
xhr.open('GET', '../data/employees.json');
xhr.send();
console.log("Hi");
Greg McDonald
7,255 PointsHi team,
Thanks for looking into this.
Please see snapshot of the code below:
(https://w.trhou.se/51cbe1db0p)
Whats strange is that in this link above, the source code <script src="js/widget.js"></script> does not appear, but this is definitely in the index.html file. This line should be on line 8, but as you can see its blank. This is the same thing that is happening when I preview the code in the browser. Its as if its not able to ride that one line of code?
It must be related to this, but I can't see what I'm doing wrong.
Greg McDonald
7,255 PointsHi team,
Thanks for looking into this.
Please see snapshot of the code below:
(https://w.trhou.se/51cbe1db0p)
Whats strange is that in this link above, the source code <script src="js/widget.js"></script> does not appear, but this is definitely in the index.html file. This line should be on line 8, but as you can see its blank. This is the same thing that is happening when I preview the code in the browser. Its as if its not able to ride that one line of code?
It must be related to this, but I can't see what I'm doing wrong.
Greg McDonald
7,255 PointsAaaaannnd its working now
KRIS NIKOLAISEN
54,971 PointsKRIS NIKOLAISEN
54,971 PointsCan you post a snapshot of your workspace? It is the camera icon in the upper right corner. Here is one with your code pasted in that is functional logging to the console