简体   繁体   中英

Javascript page reload or Meta Tag refresh method?

I looking to add a script to my aspx page that will refresh/reload the page every 15secs. There is dynamic data on my page that is sourced from Oracle. I found that I can use Javascript "reload" or the Meta Tag method, which is the best method to use to refresh a page with dynamic data?

Thanks alot!

You can use

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

but it has also drawbacks. For example if the user load the next page before 15 sec. You may get some anexpected browser reloads

using javascript you may do something like

window.setTimeout(function(){window.location.href=window.location.href},15000);

You could use setInterval in combination with an $ajax request:

setInterval(function(){
   $.ajax({
  url: someUrl,

  context: $('#myDiv')
}).success(function(data) { 
  $(this).html(data);
});
},15000);

I believe the meta tag way is only used on page load to reload the page. This method is good because it doesn't use any javascript, so if there is a problem then the page will still reload. However this tag is seen as spam to spiders. If you are wanting to redirect after page load. I'd recommend the javascript version. If not I normally do both so the page redirects as fast as possible.

There are newer ways to deal with data refreshing that are more robust. You might consider looking into web sockets .

These are low latency live connections between the web browser and the server that allow messages (data) to be sent back and forth.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM