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
simhub
26,544 PointsExtra Credit Create a Lorem Ipsum generator site in Node.js.
I took the extra credit challenge in the 'Build a Simple Dynamic Site with Node.js' course to create a Lorem Ipsum generator site in Node.js. <br/> link to my github repositorie: https://github.com/SimHub/Simple-lorem-ispum-generator
Problem or question:
how use url - request/response in a way that i can load specific content into a page without reloading the entire page over and over again?
2 Answers
Maxwell Carlson
7,265 PointsYou can also check out the MDN with https://developer.mozilla.org/en-US/docs/AJAX/Getting_Started, looking like a great place to start! Some example AJAX looks like this:
Create an HTTP request -
var xhr = new XMLHttpRequest();
Handling the servers response (example from my work in the AJAX course) -
xhr.onreadystatechange = function () {
if(xhr.readyState === 4 && xhr.status === 200) {
var employees = JSON.parse(xhr.responseText);
var statusHTML = '<ul class="bulleted">';
for (var i=0; i<employees.length; i += 1) {
if (employees[i].inoffice === true) {
statusHTML += '<li class="in">';
} else {
statusHTML += '<li class="out">';
}
statusHTML += employees[i].name;
statusHTML += '</li>';
}
statusHTML += '</ul>';
document.getElementById('employeeList').innerHTML = statusHTML;
}
};
Maxwell Carlson
7,265 PointsLoading content onto a page without reloading the entire page can be done using AJAX, which they have great videos about in this course http://teamtreehouse.com/library/ajax-basics
simhub
26,544 PointsHi Maxwell, thanks for the suggestion :) I will try this course and see how i can integrate ajax to my node project
Maxwell Carlson
7,265 PointsNo problem! If that's what you were looking for and it works out please credit me with a best answer :). Trying to get my points up in the forum for the Career Program!