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

javascript - automatic reload of div container - Stack Overflow

programmeradmin3浏览0评论

instead of a whole page refresh after a certain time, i'd just like a specific div container to reload/refresh. is there any way to do this?

<div id="wrapper">
<div id="quoteContainer"></div>
</div>

instead of a whole page refresh after a certain time, i'd just like a specific div container to reload/refresh. is there any way to do this?

<div id="wrapper">
<div id="quoteContainer"></div>
</div>
Share Improve this question edited Apr 7, 2010 at 18:48 input asked Apr 7, 2010 at 18:42 inputinput 7,51925 gold badges97 silver badges150 bronze badges 1
  • use jQuery.ajax, parse what you server returns, take div#wrapper content from ajax response and put it into div#wrapper – vittore Commented Apr 7, 2010 at 18:44
Add a ment  | 

3 Answers 3

Reset to default 5

You can get the effect you desire with jQuery and Googles ajax api

<script type="text/javascript" src="http://ajax.googleapis./ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
var auto_refresh = setInterval(
function ()
{
   $('#load_latest_scores').load('latest_scores.html');
}, 10000); // refresh every 10000 milliseconds
</script>
<body>
<div id="load_latest_scores"> </div>
</body>

If you had a page that served quotes, like quote.html for example, you could do this:

setInterval(refreshQuote, 10000); //every 10 seconds

function refreshQuote() {
  $("#quoteContainer").load("quote.html");
}

In this case the expected return from quote.html (or whatever source you have) it a simple string that is the quote, it will take this and replace the content of <div id="quoteContainer"></div> with it.

i think that one aproach would be

<script>
function render (){
$('#mydiv').html("<b>new stuff</b>")
}
window.setInterval(render, 500);
</script>
发布评论

评论列表(0)

  1. 暂无评论