How to refresh php script inside a html bric (or a complete blocs) every xx seconds

Hello,
I have added a html bric with some php code inside, for instance a simple code to add the date, for instance:
<?php echo date('H:i:s'); ?>

I would like to “refresh” this bric every second without having to refresh the page.

Them, how could I refresh an entire bloc every xx seconds?

How can I achieve this? Please help.
Thanks,
Dan

With a bit more code you can have it refresh every second, but I have a quick question first, do you want it to display your local server time, or the users local time?

No, actually I do not need to display time, it was just an example. My pho script reads a WiFi meter and I want to display update consumption.

Can you please advise how to refresh the DIV and/or the bloc?

Oh right. Normally you would have a time interval in the code itself. Can you modify the code? Or is it an iframe widget? @Pealco most likely can help here.

Yes, I can modify the code, no problem.
Best would be to refresh every XX ms an entire bloc, otherwise bric by bric

Hello @dcaccount try to do like this:

    1. Add this code to page settings code:
<script type="text/javascript">
   var autoLoad = setInterval(
   function ()
   {
      $('#content_to_update').load('consumption.php').fadeIn("slow");
   }, 10000); // refresh page every 10 seconds
</script> 
    1. In your page you add a div bric and give it the ID “content_to_update”
    1. Have a consumption.php file with the content you need…

Hope it helps you…

1 Like

Hello @Pealco,
Thanks for the suggestion.

As I have several div that need update in a bloc, shall I write a different function for each div to be updated or can I call the function with an argument, i.e. the name of the php file to update the div?

Or, as an alternative, is there a chance to update an entire bloc?

Thanks,
Dan

If you have different values and you have different places is better to update each one, as if is not by this way, it will be simpler to you one of two solutions:

  1. Have a iframe and change only one page in blocs app and the main page updates as the page is upgraded.

  2. Or have a php with all the bloc and you call the php as an iframe, as this way you can create a script to affect element inside your php.