I am using this extension for commenting in my site. It registers jquery function in a widget ECommentsListWidget .When i called this widget by ajax call the jquery file does got registered.
Here is what i have tried.
Instead of widget creating default id i manually assign a static one to test for widget
<div id="comment_area">
</div>
<?php $options = CJavaScript::encode(array(
'dialogTitle' => Yii::t('msg', 'Add comment'),
'deleteConfirmString' => Yii::t('msg', 'Delete this comment?'),
'approveConfirmString' => Yii::t('msg', 'Approve this comment?'),
'postButton' => Yii::t('msg', 'Add comment'),
'cancelButton' => Yii::t('msg', 'Cancel'),
));
$id='ywtk';//exit;
?>
<script>
$.ajax({
url:"<?php echo Yii::app()->createUrl('/site/comment'); ?>",
data:{},
type:"GET",
dataType:"html",
success:function(response){
$('#comment_area').html(response);
<?php
$js = "jQuery('#{$id}').commentsList($options);";
Yii::app()->getClientScript()->registerScript('ECommentsListWidget#'.$id, $js);
?>
}
});
</script>
I have tried by registering file in view page and then bind it in ajax call. it shows jQuery file and bind code when i inspect by firebug. as
/*<![CDATA[*/
jQuery(function($) {
jQuery('#ywtk').commentsList({'dialogTitle':'Add comment','deleteConfirmString':'Delete this comment?','approveConfirmString':'Approve this comment?','postButton':'Add comment','cancelButton':'Cancel'});
});
/*]]>*/
But now the problem is as comment area html is generated by ajax call and on that id the jQuery function has to bind.
I refered following links also
clientscript with in ajax request
please help me how i can achieve it