If I want a whole page to reload every N seconds, I would put something like this in the HTML:
meta http-equiv="refresh" content="5"
Is there a standard practice for doing the same kind of thing for AJAX calls? I want schedule an AJAX call to go off every 10 seconds say, in order to update parts of the page, without refreshing the whole page. It would be even better if I could schedule multiple AJAX calls at different times, as some parts of the page may need to be updated more often than others.
TIA
You could use
setTimeout
orsetInterval
(the latter is probably best suited to what you want to do)....where
makeRequest
is a function that reloads some content via AJAX.I assume that there is a servlet with URL Pattern /UpdateCount is configured in web.xml to provide dynamic data/content and there is a div element countStatDiv in the jsp page.
The following code refreshes/updates the content of countStatDiv at every 30 seconds using GET method and variable seconds value can be changed according to the need: