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 (retiring) Programming AJAX Parsing JSON Data

Uncaught SyntaxError: Unexpected token / ... widget.js line 5

here is my code... why am I getting this error

var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
    if(xhr.readyState === 4){
        if(xhr.status === 200){
            var info = JSON.parse(xhr.responseText);
        }
    }
}
xhr.open('GET', 'info.json');
xhr.send();

4 Answers

Dave McFarland
STAFF
Dave McFarland
Treehouse Teacher

Wendell Pulsipher

Sounds like the info.json file isn't a valid JSON file. Have you tried checking the info.json file in jsonlint,com to see if it validates?

Dave McFarland I have to wonder... could it be a browser issue?

I really need help with this right away please.. i have a project to get done

I pasted it into the validator but it ran an error because of the comment in the info.json file, so I took out the comment and now it works fine. Thank you.