Ajax page updates on a timer


I’m following a post on how to implement AJAX updates by using the built in functionality in Yii. The post is here: http://www.yiiframework.com/wiki/49/update-content-in-ajax-with-partialrender/

In that post, the author describes how to do it but he uses an "ajaxbutton" I was wondering if you could perform the same functionality on a timer, so that the page would refresh every 30 seconds or whatever you would want. I think I know how I could do it by hand but is there any built in functionality that would save me some time and allow me to keep utilizing the prebuilt functionality in Yii?



Well… I’m calling my AJAX this way (example):

<script type="text/javascript">



    	function getAJAXResults(div, id, level)





                    	'url':'/www/zlecenia/ajaxgetparams/' + id + '.html?level=' + level,

                    	'success':function(html){showAJAXResult(div, html)},

                    	'error':function(xhr, desc, er){showAJAXResult(div, xhr.responseText)}



    	getAJAXResults("#section_2_div", <?php echo($model->ID) ?>, 0);



So - as you can see - my AJAX is being fired immediately after browser reports end of page load. You can use the same function but put it into some combination of JavaScript Timing Events to have first fire of AJAX delayed by some time or to have it repeated after certain period of time passes - just like you wanted to do it.

So - to answer your question - I’m personally doing this by hand, as for me this is too simple code / functionality to look for build-in Yii feature for this. But I don’t deny, it exists! :) I just found that writing this myself wasted less time than to look for it in a huge Yii documentation! :)

You might wanna take a look at this:


and pass the url like in the wiki CController::createUrl(‘helloWorld/UpdateAjax’);

Or… you can actually do something nicer, like reading some articles about commet or realtime ajax