How can i reload $file with ajax or javascript each 5 seconds?

<?php
   if ('' == file_get_contents($file))
    {
      echo '<div id="shadow">Nobody has commented yet. Be the first? </div>';
    }
   else
    {
      include($file);
    }
?>

Recommended Answers

All 5 Replies

But how can i put that in php?

u said u have ajax, so you can make ajax call (which calls php file) and update div at every 5 seconds

no i don't have ajax. I've done this so fare

<?php
   if ('' == file_get_contents($file))
    {
      echo '<div id="shadow">Nobody has commented yet. Be the first? </div>';
    }
   else
    {
      // include($file);
?>

<script>
myFunction();
function myFunction()
{
setInterval(function(){<?php include($file); ?>},3000);
}
</script>
<?php
 }
?>

but it doesn't work :(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.