automatic reload of div container

前端 未结 3 1319
忘掉有多难
忘掉有多难 2020-12-17 05:31

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?

相关标签:
3条回答
  • 2020-12-17 05:55

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

    <script type="text/javascript" src="http://ajax.googleapis.com/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>
    
    0 讨论(0)
  • 2020-12-17 06:09

    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.

    0 讨论(0)
  • 2020-12-17 06:11

    i think that one aproach would be

    <script>
    function render (){
    $('#mydiv').html("<b>new stuff</b>")
    }
    window.setInterval(render, 500);
    </script>
    
    0 讨论(0)
提交回复
热议问题