Automatically refresh the page every 30 seconds
P粉101708623
P粉101708623 2023-08-24 00:43:45
0
2
681
<p>I have a JSP page that has to display the status of various jobs that are running. Some of these jobs take time, so it takes a while for their status to change from Processing to Completed. </p> <p>Is it a good idea to have a JavaScript function that refreshes the page every 30 seconds or so? Would there be any impact using a script that constantly refreshes the page? </p> <p>Another option is to have a refresh button, which when clicked will refresh the page. </p>
P粉101708623
P粉101708623

reply all(2)
P粉951914381

Just a simple line of code in the head section can refresh the page

Although it is not a JavaScript function, it is the easiest way to accomplish the above task.

P粉421119778

There are multiple solutions to this. If you wish to refresh the page, no JavaScript is actually required, the browser can do this for you if you add this meta tag inside the head tag. p>

<meta http-equiv="refresh" content="30">

The browser will refresh the page every 30 seconds.

If you really want to do this using JavaScript, you can use Location.reload() to refresh the page every 30 seconds (docs) in setTimeout() middle:

window.setTimeout( function() {
  window.location.reload();
}, 30000);

If you don't need to refresh the entire page, but only a part of it, I think an AJAX call would be the most efficient method.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template