Answer the question
In order to leave comments, you need to log in
How to organize ajax update of element with id="myElem" in Yii?
There is an element with id="myElem". The data is output to it via renderPartial.
I need to update the content of this element via ajax.
It is possible through CHtml::ajaxLink, which has a cool update parameter. But this option is not suitable. The content of the element should change when a value is selected from the drop-down list.
How to update the content of an element after an ajax request in yii without CHtml::ajaxLink?
Answer the question
In order to leave comments, you need to log in
public function actionAjaxUpdate(){
if(Yii::app()->request->isAjaxRequest){ // только ajax
$this->layout = false; // отключим шаблон
$this->render('то что тащит рендер', array(
'params'=>$params
));
}
else
throw new CHttpException(404, 'Запрашиваемая страница не существует.');
}
<div id="myElem">
<?php $this->renderPartial('//то что тащим', true, false, array(
'params'=>$params
)) ?>
</div>
$('#link').click(function (e){
e.stopPropagation();
var update = $('#myElem');
$.ajax({
'type': 'POST',
'url': '/AjaxUpdate',
'cache': false,
'success':function(data) {
update.html(data);
}
});
});
<?php echo CHtml::link('Обновить!', '#', array('id'=>'link')) ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question