phphtmlcssmootoolsxajax

Auto refresh using xajax (and MooTools?)


For the purpose of testing (and making this question simpler) I have been using xajax to output a random number into a DIV on the page.

$output=rand(20,40);

$ajax_resp->assign('container','innerHTML', $output); 

After the DIV container is loaded, I also load 1 line of Javascript to call the xajax function.

<div id="container"></div>
<script type="text/javascript">
  xajax_refresh().periodical(2000);
</script>

As you can see, I'm using the MooTools function called periodical() to call the function again after x milleseconds. It calls the function fine at first, but not again.

It doesn't automatically refresh. Why?


Solution

  • You are not assigning a periodical to xajax_refresh function, you are calling that function (with xajax_refresh()). For instance, you're assigning its returned value to periodical (It can be everything, but nothing happens because that returned value is not a function :) ).

    Therefore, the solution is this:

    <script type="text/javascript">
      xajax_refresh.periodical(2000);
    </script>