Javascript repeat every X seconds

Categorías: 

Etiquetas: 

  • Javascript
function updateData() {
$.ajax({
        'type':'get',
        'url':'ajaxExample.php',
        'cache':false,
        'success':function(data){
                $('#ajax-example-results').html(data);
            }
        }        
    });
}
 
updateData();
// refresh every 5 seconds
var auto_refresh = setInterval(function(){ updateData() }, 5000);
  • Server part (PHP example)
  // echo whatever every 5 seconds in #ajax-example-results 
  echo $output;
}