I’ve tested and … I have good news ![]()
-
It's working
-
It's working without unique ID's (tested under FF and Konqueror, someone could test it with IE).
SiteController.php:
public function actionAjaxUpdate() {
$this->renderPartial('ajaxUpdate');
}
someware in views/site/index.php :
$this->renderPartial('ajaxUpdate');
and the most important part views/site/ajaxUpdate.php:
<div id="target">
<?php echo CHtml::link("Test AjaxUpdate", '#', array('id'=>'testlink')); ?>
<h2><?php $df = new CDateFormatter('en'); echo $df->formatDateTime(time()); ?></h2>
<script type="text/javascript">
function initTarget() {
jQuery('#testlink').click(function(){jQuery.ajax({'url':'/frk/yii_test3/index.php?r=site/ajaxUpdate','cache':false,'success':function(html){
jQuery("#target").replaceWith(html);
initTarget();
}});return false;});
}
</script>
<?php Yii::app()->getClientScript()->registerScript('target', 'initTarget();'); ?>
</div>
Please remember to set correct url in JS ajax request …
So i think that:
-
registerScript should have ability to register script in view's body in js function.
-
renderPartial should render script block with this init function where would be registered all scripts from widgets.
-
all widgets which use js, when are rendered by renderPartial() method should register their initialization script in view's body.
-
these widgets should register init function in global document.ready (for first time initialization when whole page is loaded)