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 Processing JSON Data

Nour El-din El-helw
Nour El-din El-helw
8,241 Points

I don't know what I'm doing wrong

For some reason nothing appears in my HTML that's generated by JS , I checked all my code and I don't see anything wrong. I'm using Visual Studio code and using a local host(MAMP) so I can do the AJAX request. I've put my code into the workspace for this video so I can make a snapshot of it. So here it is https://w.trhou.se/jmv8pxs45d . EDIT: I tried it in the workspace and it worked so can someone please explain this?

1 Answer

Steven Parker
Steven Parker
231,268 Points

It's not an error for "statusHTML" to be "undefined" in the console. Since it's declared inside the handler function for onreadystatechange, it's scope is limited to that function.

If you'd like to be able to examine it from the console, you might want to declare it outside the function as a global.

Nour El-din El-helw
Nour El-din El-helw
8,241 Points

Oh right, I don't know how I missed that! But This isn't the main problem, the problem is nothing appears in my HTML that's generated by JS when I'm using my own editor and MAMP( local host ) but when I use the workspace it works.

Steven Parker
Steven Parker
231,268 Points

I'd guess there's some configuration difference between the workspace and the other system that's affecting the outcome. Adding a few "hooks" like global values to assist with debugging might be a good idea. Knowing exactly what point in the program is failing may help to identify the issue.

Nour El-din El-helw
Nour El-din El-helw
8,241 Points

I've figured out what's the problem! It was really silly actually, I was in the wrong folder instead of 'video 6' I was in the folder for 'video 5' so there wasn't the div 'roomList' even which I should've put my HTML into. Sorry I wasted your time. ;(

Steven Parker
Steven Parker
231,268 Points

Answering an earnest question is never a waste. Glad I could help, and happy coding!