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 trialmartingustafsson
3,585 PointsAJAX does not load
My AJAX div does not load. What is wrong. example1.html and example2.html doesn't work either. Here's my code: https://teamtreehouse.com/workspaces/23288522
Thanks a bunch!
6 Answers
Artem Shturkin
Courses Plus Student 8,359 PointsOne more thing
xhr.onreadyStateChange = function() { //wrong
xhr.onreadystatechange = function() { //right, use lower case letters
Artem Shturkin
Courses Plus Student 8,359 PointsSo, finaly I get it! I suppose that the problem was , that you wanted to preview the workspase, editing the example2.html, during the workspace preview shows you the result stored in index.html, so change the code in index.html file , and you will get a result.
martingustafsson
3,585 PointsI got it. Rename to index.html to preview that specific file (example1 & 2). Thank you There has to be something wrong with the code that i posted above though. I don't get any errors in console or the Ajax content to show up.
Artem Shturkin
Courses Plus Student 8,359 Pointsdont forget to choose best answer to close se discution
martingustafsson
3,585 PointsBut the problem is not solved. There is a problem with the code that i posted above^
Artem Shturkin
Courses Plus Student 8,359 PointsIts works, try to add console.log(xhr.responseText); to see that you get
Daniel Arnost
7,190 PointsIt does not work! Copied and pasted the code given above although I had already found the error. Also this is a completely different (glad to know more ways) but much more complicated way to make ajax requests than I previously was taught.
Avery Kachline
12,824 PointsI tried to us Firefox browsers and Google Chrome both of them example to with the button does not work. Maybe we just need to you our own local sever or just use a remote one from a hosting company. For whatever reason I cannot, get example 2 to run on [Workspaces].
martingustafsson
3,585 PointsOh. sorry! here it is:
<script>
var xhr = new XMLHttpRequest(); // step 1
xhr.onreadyStateChange = function() { // step 2
if(xhr.readyState === 4) {
document.getElementById('ajax').innerHTML = xhr.responseText;
}
};
xhr.open('GET', 'sidebar.html'); // step 3
xhr.send(); // step 4
</script>
Artem Shturkin
Courses Plus Student 8,359 PointsArtem Shturkin
Courses Plus Student 8,359 PointsHello, if you want to get help, please write the code directly in the question, because the workspase/preview of workspace is closed.