CodeIgniter Forums

Full Version: Ajax Framework (CJAX) Refresh a <DIV> each X seconds
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Unknown[/eluser]
Hi,
I installed CJAX and made some little tests and seem working.
Now I'm facing the problem to refresh a <div> each X seconds.
Let's say I'd like to display the current time.
I did't find any clue, and of course I'm absolutely not a js expert.
Can someone help me?
Thanks in advance for the help.
P.

El Forum

[eluser]noideawhattotypehere[/eluser]
Code:
setInterval(function(){ $.get(...), 500 }
this would call that function each 500ms. you could do that in your view with plain jquery/js

El Forum

[eluser]Ajaxboy[/eluser]
Code:
//in your controller
$ajax->call('ajax.php?my_controller/my_function","div_Id");

//in  your response
class My_controller {

public function my_function()
{
$ajax = ajax();
$ajax->wait(5);// wait 5 seconds
$ajax->call('ajax.php?my_controller/my_function","div_Id"); //repeats operation after 5 seconds
echo date("j, n, Y", time());  // prints the date/time, which will be returned to the div.
}


}

There is a wait() function allows you to do time interactions, there is not an interval function but that is a good idea to add in a future release. The above code should get the job done.