【发布时间】:2015-02-16 07:03:01
【问题描述】:
在视图页面中我有 2 个下拉菜单
<?php
$list = CHtml::listData($category,
'cid', 'cname');
echo $form->dropDownList($model,'cid',$list,
array('empty' => '(Select a category)'));
?>
<label>Sub Category *</label>
<?php
$subcategory = array();
echo $form->dropDownList($model,'sid',$subcategory,
array('empty' => '(Select a subcategory)'));
?>
使用类别中的值我必须更改子类别值
这是我的 ajax 函数
<script type="text/javascript">
$(function (){
$("#Product_cid").change(function (){
var cid = $('#Product_cid').val();
var path = "<?php echo $this->createUrl('admin/mysubcategory') ?> ";
$.ajax({
type: "POST",
url: path, //url to be called
data: { cid: cid } //data to be send
}).done(function( msg ) {
alert(msg)
$("#Product_sid").val("msg");
$("#Product_sid").selectmenu('refresh');
.
});
});
});
</script>
这是我的控制器
public function actionMysubcategory()
{
$cid = Yii::app()->request->getPost('cid');
$subcategory= Subcategory::model()->findAll(
array('order'=>'sid',
'condition'=>'cid=:cid',
'params'=>array(':cid'=>$cid)));
$list = CHtml::listData($subcategory,
'sid', 'sname');
print_r($list);
}
我从控制器获取列表。怎么可以做成下拉菜单???
【问题讨论】:
-
响应的内容和效果如何?
alert(msg)...
标签: jquery ajax post drop-down-menu yii