无法在yii中将数据发布到测量控制器

时间:2017-04-22 09:05:55

标签: yii

的index.php

<?php
Yii::app()->clientScript->registerScript('items_update', 
"$('#dropit').change(function(){
    $.ajax({
        url: '".Yii::app()->createUrl('survey/questions')."',
        data:
            {
                _designation : test,
            },
        type: 'POST',
        success:function()
            { 
                console.log('success');
            },
        error:function()
            { 
                console.log('failure');
            }
        });
    return false;
    });    
");
?>


<div id="surveyupdate">
<?php 
    echo CHtml::dropDownList('dropit', '', 
     array(                                             
  'Reception'=>'Service Reception', 
  'SA'=>'ServiceAdvisor','Billing'=>'Billing Staff',          
  'Parts'=>'Parts Counter','Cashier'=>'Cashier','Cwd'=>'Customer Welfare Desk'),
     array('prompt'=>'- select -'));
?>
</div>

<?php
$this->widget('zii.widgets.CListView', array(
            'dataProvider'=>$dataProvider,
            'itemView'=>'_view',    
            'id'=>'ajaxListView',
            ));
?>

控制器'survey.php'

 public function actionQuestions()
{   
    //debugging purposes
    echo "<pre>";
    print_r($_POST);
    exit;
}

待办事项

我要做的是更新 CListView ,方法是通过下拉列表下拉列表获取所选数据控制器,从数据库获取数据并更新 CListview

请帮帮我。我刚刚学习Yii。谢谢!

1 个答案:

答案 0 :(得分:0)

您需要为dropdownList添加Id,如下所示

echo CHtml::dropDownList('dropit', '', 
     array(                                             
  'Reception'=>'Service Reception', 
  'SA'=>'ServiceAdvisor','Billing'=>'Billing Staff',          
  'Parts'=>'Parts 
  Counter','Cashier'=>'Cashier','Cwd'=>'Customer Welfare 
  Desk'),
 array('prompt'=>'- select -', 'id'=>'dropit')); // added I'd here