view.php will be visible to user ie it will show the clock and response.php is the ajax page which will send the latest time.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Comet demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" / >
<script type="text/javascript" src="
</script>
</head>
<body>
<div id="comet_frame" style="display:none;visablity:invisable;"></div>
<div id="content"></div> <br />
</body>
</html>
<script type="text/javascript">
var comet =
{
load: function()
{
$("#comet_frame").html('<iframe id="comet_iframe" src="response.php"></iframe>');
},
unload: function()
{
$("#comet_frame").html('<iframe id="comet_iframe" src=""></ iframe>');
},
clearFrame: function()
{
$("#comet_iframe").html("");
},
timer: function(result)
{
$("#content").html(result);
}
}
$(document).ready(function()
{
comet.load();
});
</script>
<?php
function flushHard()
{
// echo an extra 256 byte to the browswer - Fix for IE.
for($i=1;$i<=256;++$i)
{
echo ' ';
}
flush();
ob_flush();
}
set_time_limit(0);
header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
flushHard();
$x = 0;
while(1)
{
if($x == 10)
{
echo '<script type="text/javascript">parent.comet.clearFrame();</script>'."\n";
}
else
{
echo '<script type="text/javascript">parent.comet.timer("'.date('H:i:s').'");</script>'."\n";
}
flushHard();
++$x;
sleep(1);
}