Answer the question
In order to leave comments, you need to log in
A hackneyed question - ajax+CHtml::dropDownList, doesn't work please?
Good health to all, please help me figure out how to send a POST select via ajax. Here is the code:
echo CHtml::dropDownList('listname', 'bla',
$model,
array('empty' => 'Марка авто',
'style'=>'width:155px',
'class'=>'btn btn-default dropdown-toggle',
'ajax' => array(
'type' => 'POST',
'url' => CController::createUrl('site/getMod'),
//'data'=> array(
// 'id'=>'js:this.value',
// 'YII_CSRF_TOKEN' => Yii::app()->request->csrfToken),
'update' => '#sub_cat_id',),
));
public function actionGetMod()
{
$ff = array();
return $ff;
}
actionGetMod($id)
<div id="sub_cat_id">
<?php print_r($ff); ?>
</div>
Answer the question
In order to leave comments, you need to log in
In general, for a long time I will smoke all kinds of scriptures, there are thoughts in the direction of CHtml::$liveEvents = FALSE; but it’s of little use, I don’t have ice with JavaScript either, it turns out the following heresy, which I didn’t expect from myself and from my Yii:
The first select is in my view and there are no problems with it
CHtml::$liveEvents = FALSE;
echo CHtml::dropDownList('listname', 'bla',
$model,
array('empty' => 'Марка авто',
'style'=>'width:auto',
'class'=>'btn btn-default dropdown-toggle',
'ajax' => array(
'type' => 'POST',
'url' => CController::createUrl('site/getMod'),
'data'=> array(
'id'=>'js:this.value',
'YII_CSRF_TOKEN' => Yii::app()->request->csrfToken),
'update' => '#sub_cat_id',
),
));
public function actionGetMod()
{
CHtml::$liveEvents = FALSE;
if(Yii::app()->request->isAjaxRequest){
if(isset($_POST['id'])){
$f= Mod::getModelData($_POST['id']);
echo CHtml::dropDownList('modelky', 'mode',
$f,
array( 'empty' => 'Модель авто',
'style'=>'width:155px',
'class'=>'btn btn-default dropdown-toggle',
'ajax' => array(
'type' => 'POST',
'url' => CController::createUrl('site/getVar'),
'data'=> array(
'id_v'=>'js:this.value',
'YII_CSRF_TOKEN' => Yii::app()->request->csrfToken),
'update' => '#var',
'succes' => 'function(){$("#var").change();}',
),
));
}
}
}
/*<![CDATA[*/
jQuery(function($) {
jQuery('#listname').on('change', function(){jQuery.ajax({'type':'POST','url':'/site/getMod','data':{'id':this.value,'YII_CSRF_TOKEN':'d02ef985c3400d717ee866ede2af6610af42b446'},'cache':false,'success':function(html){jQuery("#sub_cat_id").html(html)}});return false;});
});
/*]]>*/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question