Auto refresh page every 30 seconds

前端 未结 4 1902
甜味超标
甜味超标 2021-01-30 16:30

I have a JSP page which 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

4条回答
  •  被撕碎了的回忆
    2021-01-30 16:35

    There are multiple solutions for this. If you want the page to be refreshed you actually don't need JavaScript, the browser can do it for you if you add this meta tag in your head tag.

    
    

    The browser will then refresh the page every 30 seconds.

    If you really want to do it with JavaScript, then you can refresh the page every 30 seconds with location.reload() (docs) inside a setTimeout():

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

    If you don't need to refresh the whole page but only a part of it, I guess an Ajax call would be the most efficient way.

提交回复
热议问题