Updating part of the page in ajax

How to organize automatic updating (in 5-10 seconds) of a part of the page.


Answer 1, authority 100%

var intevalHandler = setInterval('reload()',7500); //  7500

The reload function must contain an ajax request.
Fully:
HTML:

<div id='updateMe'>
<span id='girl_name'></span> 
<span id='relationship'></span> 
<span id='boy_name'></span> 
</div>

JQuery:

var reloadFunction;
$(document).ready(function(){
  reloadFunction = function(){
    $.post('rel.php',{'some_query_var':'foobar'},function(data){
      data = eval('('+data+')');
      $("#girl_name").text(data.girl_name);
      $("#relationship").text(data.relationship);
      $("#boy_name").text(data.boy_name);
    });
   }
   var intevalHandler = setInterval('reloadFunction()',7500);
});

rel.php:

$girl_name = array('','','','','');
$relationship = array('',' ',' ','','  ');
$boy_name = array('','','','','');
$girl_rand_max = count($girl_name)-1;
$relationship_rand_max = count($relationship)-1;
$boy_rand_max = count($boy_name)-1;
printf('{"girl_name":"%s","relationship":"%s","boy_name":"%s"}',$girl_name[rand(0,$girl_rand_max)],$relationship[rand(0,$relationship_rand_max)],$boy_name[rand(0,$boy_rand_max)]);

If you didn’t mess up anything, it should work.


Answer 2, authority 50%

AJAX

<div id="content"></div>
<script>  
    function show()  
    {  
        $.ajax({  
            url: "time.php",  
            cache: false,  
            success: function(html){  
                $("#content").html(html);  
            }  
        });  
    }
    $(document).ready(function(){  
        show();  
        setInterval('show()',1000);  
    });  
</script>

in the content block, the script time.php will be displayed And updated – setInterval(‘show()’,1000);