最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I reload page at every 15 seconds? - Stack Overflow

programmeradmin3浏览0评论

I build one web Application in Wolfram Mathematica,what it does it displays the DB data directly on the browser.

I placed my Application in Apache Tomcat.

I want to reload this page for every 15 seconds,because If you reload the page we will get updated data of DB.

How can I do this?

I build one web Application in Wolfram Mathematica,what it does it displays the DB data directly on the browser.

I placed my Application in Apache Tomcat.

I want to reload this page for every 15 seconds,because If you reload the page we will get updated data of DB.

How can I do this?

Share Improve this question edited Jun 24, 2014 at 2:48 rink.attendant.6 46.2k63 gold badges110 silver badges157 bronze badges asked Jun 23, 2013 at 10:22 subbusubbu 5624 gold badges8 silver badges21 bronze badges 2
  • 2 Please put "javascript reload page" to the google and read the results – zerkms Commented Jun 23, 2013 at 10:24
  • This is an absolute AJAX situation...please refer to passionateCoder's comment – py_script Commented Jun 23, 2013 at 10:49
Add a comment  | 

4 Answers 4

Reset to default 12

Add a script like this in the head section of the page:

<script type="text/javascript">
window.setTimeout(function(){ document.location.reload(true); }, 15000);
</script>

The setTimeout method will start the callback after 15 seconds, and the reload method will reload the page. The true parameter makes the browser always request the page again instead of possibly using a cached version.

That's bad isn't it? Reloading a page once in 15 secs will break the user experience completely. A user will not be able to even read the page properly to get the context in 15 secs.

Why not use ajax to get results to update the container which contains the data once in 15 secs? By that you'll give the user updated info.

$.ajax({
  type: "POST",
  url: "some.php", //some server method which will get u new data from database
  data: { name: "John", location: "Boston" }
}).done(function( msg ) {
  var i= 0;
  for(; i< msg.d.length; i++)
  {
    $("#container").append(msg.d[i]);
  }    
});

Where #container is where you have the data represented.

AJAX Docs : http://api.jquery.com/jQuery.ajax/

Just add <meta content='15' http-equiv='refresh'/> between <head></head>. Change the number that you need, like if you need your page to load after 30 secs, then change the value 15 to 30.

<head>
<meta content='15' http-equiv='refresh'/>
</head>

The following code in the head section of an HTML document will also refresh the page without using any JavaScript:

<meta http-equiv="refresh" content="15" />
发布评论

评论列表(0)

  1. 暂无评论