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 trialNas Jones
7,849 PointsMultiple questions
There's alot that confuses me here. What is the purpose of AJAX here? Can't all of this be done with JS and DOM? Was our purpose here to just keep it on the same webpage?. Also, what does sidebar.html have anything to do with this?.
2 Answers
Bert Witzel
Full Stack JavaScript Techdegree Graduate 27,918 PointsHi Nas, fetch(), which you will learn about at some point in your Treehouse journey, is a better and more recent alternative to XMLHttpRequest
but it can be good to know the history of AJAX requests and their different formats because you do see them out there in the wild from time to time. When you work with API's you are requesting information from a third party application, so you cannot accomplish what you want to do just in the DOM.
Laura Dangler
3,301 PointsSeems like you know the answer already why do you ask questions if you know the answer? lol
Nas Jones
7,849 PointsNas Jones
7,849 PointsHello thank you for answering. I kind of get what you're trying to say with fetch being more recent but i'm still confused i don't see how any of my questions were answered? like what does sidebar.html have anything to do with this and what was our purpose in this video? why not use just DOM to do what we did in the video is it to keep it on the same webpage?
Bert Witzel
Full Stack JavaScript Techdegree Graduate 27,918 PointsBert Witzel
Full Stack JavaScript Techdegree Graduate 27,918 PointsHi Nas, I see what you are saying. I just watched the whole video to get a better context for your questions. So in this video Dave is making an AJAX request to a file that is already in the workspaces, since he is trying to teach us how an AJAX request works. But in real life you would make an AJAX request to an API, like a weather api, and that information is not available unless you make an API request. Here he is just trying to teach us how a request works. So yes, you could accomplish what he is doing by dynamically creating the sidebar content and inserting it into the DOM like you mentioned, but then you wouldn't be learning how an AJAX request works.
Nas Jones
7,849 PointsNas Jones
7,849 PointsHey Bert, just so I'm understanding in this video he is making a request to sidebar.html but in a real life scenario we would most likely use a request for an api if I'm not mistaken. I still don't see why do we need sidebar.html like what's the logic behind that file and our request why sidebar.html?. Also, just to wrap my head around AJAX the purpose of it is to make requests to other files or servers if possible all to accomplish the goal of getting responses while the user remains on the same webpage correct?.