You are viewing revision #1 of this wiki article.
This is the latest version of this article.
Often happens to have the need of change a part of the page with ajax.
For example, having a code like:
<div id="forAjaxRefresh"></div>
<?php echo CHtml::ajaxLink('clickMe', array('ajax'), array('update'=>'#forAjaxRefresh'));?>
It will call the actionAjax in the controller and refresh the content of the div.
What about ClientScript? ¶
And if the content we are going to replace has some script itself?
In this case the actionAjax should send even the client script needed, this can be done by setting the fourth parameter of renderpartial to true:
public function actionAjax()
{
$this->renderPartial('ajaxView', array(), false, true);
}
The fourth will make so all client script will be processed and wrote at the end of the html widget.
Pay attention that the ID are authomatically generated by yii by incrementing a counter, when you do your renderPartial, there is the possibility that the newly generated id will confilct with the id of the other part of the page.
If you have some problem with the clientscripted object (link, jui widget and so on) after an ajax update, it is possible that you have to set the id to all this items, in order to avoid this conflicts.
If you don't want to include jquery in returned html
If you do not want to include jquery script code into returnned html code you can do in view:
Yii::app()->clientscript->scriptMap['jquery.js'] = false;
Conflicting IDs
I think it it generally a good idea to specify custom IDs with the 'htmlOtions' parameter when using renderPartial to update the page.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.