How do I refresh a DIV content?

后端 未结 4 734
故里飘歌
故里飘歌 2020-12-13 14:15

I am trying to refresh a certain div within a bunch of divs. The div content is basically generated by PHP alon

相关标签:
4条回答
  • 2020-12-13 14:31

    For div refreshing without creating div inside yours with same id, you should use this inside your function

    $("#yourDiv").load(" #yourDiv > *");
    
    0 讨论(0)
  • 2020-12-13 14:31

    You can use jQuery to achieve this using simple $.get method. .html work like innerHtml and replace the content of your div.

    $.get("/YourUrl", {},
          function (returnedHtml) {
          $("#here").html(returnedHtml);
    });
    

    And call this using javascript setInterval method.

    0 讨论(0)
  • 2020-12-13 14:55

    To reload a section of the page, you could use jquerys load with the current url and specify the fragment you need, which would be the same element that load is called on, in this case #here:

    function updateDiv()
    { 
        $( "#here" ).load(window.location.href + " #here" );
    }
    

    This function can be called within an interval, or attached to a click event

    0 讨论(0)
  • 2020-12-13 14:58

    Complete working code would look like this:

    <script> 
    $(document).ready(function(){
    setInterval(function(){
          $("#here").load(window.location.href + " #here" );
    }, 3000);
    });
    </script>
    
    <div id="here">dynamic content ?</div>
    

    self reloading div container refreshing every 3 sec.

    0 讨论(0)
提交回复
热议问题