Automatically refresh the page every 30 seconds
P粉101708623
2023-08-24 00:43:45
<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>
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.
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 thehead
tag. p>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) insetTimeout()
middle: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.