Fischer asked this 8 years ago

How to refresh the contents of a div using AJAX and jQuery?

I want to refresh the content of a div periodically (eg: every 5s)


Best Answer by pseudoFish 8 years ago

HTML

<div id="my_refreshing_div"></div>

 

JS

function auto_load(){
        $.ajax({
          url: "myfile.php",
          cache: false,
          success: function(response){
             $("#my_refreshing_div").html(response);
          } 
        });
}
 
$(document).ready(function(){
    //Call autoload when page is ready
    auto_load(); 
});
 
//Call auto_load() at 5s intervals
setInterval(auto_load,5000);