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!

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 Stage 2 Challenge Answer

Nursultan Bolatbayev
Nursultan Bolatbayev
16,774 Points

How often AJAX request is sent to the server?

Is there a default period to send AJAX request to the server (in our case to know availability of rooms)? Or the server sends some notifications to the web browser to update the page if status changes?

1 Answer

I think the answer would depend upon how the code is written. You could wrap the AJAX request and processing of returned data in the following function to pull in new data about room availability at the interval you want.

setInterval(function() {
      // make AJAX call
     // Process returned data and output HTML
}, 300000)

This would run the code every 5 minutes. There is probably more involved to this, but it may be a start.

Nursultan Bolatbayev
Nursultan Bolatbayev
16,774 Points

So you mean that AJAX request interval is configurable? But what is default? We know that AJAX sends request to a server to update the data on page, can server without waiting for request send new updated data to the page and AJAX or JQuery can have kinda of callback function for that update (without sending request)?