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 trialshubrotodebnathshuvo
7,489 PointsCan I use setinterval() to load that part after few seconds interval to make it more like live feed? Mine is not working
I like to use more like a live feed version. It is like when someone change the room availability to true from false in json file and without reloading the page that part will change from green to red automatically. I tried using setinterval() and call that ajax code as a anomanus function and set the interval time to 1000 but it didn't work. Can any tell me why it did not work? And what to do to make it work?
1 Answer
Justin Coen
Full Stack JavaScript Techdegree Student 12,829 PointsI also tried this. Initially I had incorrect syntax for my setInterval() which caused my code to error out. Once I fixed my syntax errors I realized that I needed to not only set an interval on my xhr.send() but my xhr.open() as well, because after the initial request is made the request closes.
After this it worked great, updating any changes made inside the employees.json file.
setInterval(function() {
xhr.open('GET', 'data/employees.json');
xhr.send();
}, 5000);
rydavim
18,814 Pointsrydavim
18,814 PointsPlease post your code or a workspace snapshot. It's difficult to tell you what's wrong without seeing the problem.