есть widget, в нем Chtml:ajaxLink
код виджета:
Код: Выделить всё
echo CHtml::ajaxLink(
Yii::t('site','Add to favorite'),
array('/default/favorite.ajax'),
array(
'type' => 'POST',
'replace' => '#widget_id_prefix_' . $id,
'dataType' => 'html',
'data'=>array(
'fav_uid'=>$this->fav_uid,
'action'=>'add',
)
)
,array(
'id'=>'fw_link'.$id
)
);
Код: Выделить всё
шаблон: _favorites.php
$this->widget('zii.widgets.CDetailView', array(
'data' => $data,
'attributes' => array(
array(
'label' => 'Favorite',
'type'=>'raw',
'value'=> $this->widget('FavoriteLinkWidget', array(...),true),
),
),
));
Код: Выделить всё
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_favorites',
));
Код: Выделить всё
if(Yii::app()->request->isAjaxRequest)
$this->renderPartial('index', compact('dataProvider'),false, true);
else
$this->render('index', compact('dataProvider'));
ajaxLink перестают работать. page #2 приходит полностью корректная, есть скрипты, в консоле ошибок нету.
Все с первого взгляда хорошо и мне кажется что вся проблема в том что скрипты срабатывают перед тем как пагинатор вставляет новые элементы.
Ниже приведен небольшой пример контента который возвращается при аякс пагинации
Код: Выделить всё
<ul class="categoryList">
<li>
<a href="#" id="fw_link31yw1">Romance</a></li>
<li>
<a href="#" id="fw_link32yw2">Mystery</a></li>
<li>
<a href="#" id="fw_link33yw3">Thriller</a></li>
<li>
<a href="#" id="fw_link34yw4">Sci-Fi</a></li>
</ul>
// all the below stuff is written to the DOM by the ajaxLink() function using Javascript:
<script type="text/javascript">
/*<![CDATA[*/
$('body').on('click','#fw_link31yw1',function(){jQuery.ajax({'type':'POST','dataType':'html','data':{'fav_uid':'31','action':'remove'},'url':'/default/favorite.ajax','cache':false,'success':function(html){jQuery("#favorite_link_31yw1").replaceWith(html)}});return false;});
$('body').on('click','#fw_link32yw3',function(){jQuery.ajax({'type':'POST','dataType':'html','data':{'fav_uid':'32','action':'add'},'url':'/default/favorite.ajax','cache':false,'success':function(html){jQuery("#favorite_link_32yw3").replaceWith(html)}});return false;});
$('body').on('click','#fw_link33yw5',function(){jQuery.ajax({'type':'POST','dataType':'html','data':{'fav_uid':'33','action':'add'},'url':'/default/favorite.ajax','cache':false,'success':function(html){jQuery("#favorite_link_33yw5").replaceWith(html)}});return false;});
$('body').on('click','#fw_link34yw7',function(){jQuery.ajax({'type':'POST','dataType':'html','data':{'fav_uid':'34','action':'add'},'url':'/default/favorite.ajax','cache':false,'success':function(html){jQuery("#favorite_link_34yw7").replaceWith(html)}});return false;});
/*]]>*/
</script>