How to refresh table contents in div using jquery/ajax

后端 未结 1 1352
庸人自扰
庸人自扰 2020-12-14 13:31

I need your help in order to refresh a div id=\"mytable\" in my html once the function is called from a method. Currently, I am loading the full page once it is

相关标签:
1条回答
  • 2020-12-14 14:25

    You can load HTML page partial, in your case is everything inside div#mytable.

    setTimeout(function(){
       $( "#mytable" ).load( "your-current-page.html #mytable" );
    }, 2000); //refresh every 2 seconds
    

    more information read this http://api.jquery.com/load/

    Update Code (if you don't want it auto-refresh)

    <button id="refresh-btn">Refresh Table</button>
    
    <script>
    $(document).ready(function() {
    
       function RefreshTable() {
           $( "#mytable" ).load( "your-current-page.html #mytable" );
       }
    
       $("#refresh-btn").on("click", RefreshTable);
    
       // OR CAN THIS WAY
       //
       // $("#refresh-btn").on("click", function() {
       //    $( "#mytable" ).load( "your-current-page.html #mytable" );
       // });
    
    
    });
    </script>
    
    0 讨论(0)
提交回复
热议问题