Yii Framework Forum: Ajax page updates on a timer - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Ajax page updates on a timer Rate Topic: -----

#1 User is offline   nazum 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 56
  • Joined: 21-March 11

Posted 05 May 2011 - 12:34 PM


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.yiiframew...-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?



#2 User is offline   Trejder 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,257
  • Joined: 06-October 10
  • Location:Southern Poland

Posted 06 May 2011 - 05:37 AM

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! :)
Proud Cookbook author, though still learning powerful Yii! :] See my generic profile for more information. Cheers!

#3 User is offline   Asgaroth 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 371
  • Joined: 17-July 09
  • Location:Bogota, Colombia

Posted 06 May 2011 - 11:19 AM

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


- Extension: Dynamic DataProvider Behavior
- Extension: XUpload - jQuery File Upload Extension
- Extension: PhpQuickProfiler - A Web Log Router that will help you profile your application
- Extension: XDateView - A Date grouped Grid View
- Extension: Foundation - An easy to use, powerful, and flexible framework for building prototypes and production code on any kind of device.

- Wiki: How to generate Yii like Documentation
- Wiki: How to re enable logging during unit testing

Share this topic:

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users