我正在使用yii的依赖下拉列表,但是当我使用ajax发送请求时,它会发布所有表单值,但我想只发布catid并想要删除所有额外的帖子以使其变亮。下面是我的视图文件的代码请告诉我只发布catid的方法
<div class="form">
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'foodproduct-form',
'enableAjaxValidation' => false,
'htmlOptions' => array('enctype' => 'multipart/form-data'),
));
?>
<div class="row">
<p class="note">Fields with <span class="required">*</span> are required.</p>
</div>
<div class="row">
<?php echo $form->errorSummary($model); ?>
</div>
<div class="row">
<?php
$maincatAry = CommonAdminModel::getallmaincategories();
echo CHtml::dropDownList('catid', 'title', $maincatAry, array
(
'empty' => 'Select Category',
'ajax' => array
(
'type' => 'POST',
'url' => CController::createUrl('foodproduct/getajaxmaincats'),
'success' => 'js:function(data)
{
var jsonData=$.parseJSON(data);
if(jsonData.status=="nosubcatexist"){
alert("nothing found");return false;
}
var opt="<option value=>Select SubCategory</option>";
$.each(jsonData,function(i,obj)
{
opt+="<option value=\'"+obj.id+"\'>"+obj.title+"</option>";
});
$("#subcatid").html(opt);
}',
'error' => 'js:function(data){
console.log(data);
}'
)
));
?>
</div>
<div class="row">
<?php echo CHtml::dropDownList('subcatid', '', array()); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model, 'title'); ?>
<?php echo $form->textField($model, 'title', array('size' => 60, 'maxlength' => 100)); ?>
<?php echo $form->error($model, 'title'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model, 'description'); ?>
<?php echo $form->textArea($model, 'description', array('rows' => 6, 'cols' => 50)); ?>
<?php echo $form->error($model, 'description'); ?>
</div>
<div class="row">
<?php echo CHtml::activeFileField($model, 'image'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model, 'availibility'); ?>
<?php echo $form->textField($model, 'availibility', array('size' => 3, 'maxlength' => 3)); ?>
<?php echo $form->error($model, 'availibility'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model, 'status'); ?>
<?php echo $form->textField($model, 'status', array('size' => 8, 'maxlength' => 8)); ?>
<?php echo $form->error($model, 'status'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model, 'shorturl'); ?>
<?php echo $form->textField($model, 'shorturl', array('size' => 60, 'maxlength' => 255)); ?>
<?php echo $form->error($model, 'shorturl'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model, 'slug'); ?>
<?php echo $form->textField($model, 'slug', array('size' => 60, 'maxlength' => 255)); ?>
<?php echo $form->error($model, 'slug'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>
<?php $this->endWidget(); ?>
这是我的控制器的代码
public function actiongetajaxmaincats() {
$catid = $_POST['catid'];
$qryAry = Foodcategory::model()->findByAttributes(array('id' => $catid, 'subcatexistence' => 'yes'));
if (!empty($qryAry['id'])) {
$qrysubcatAry = Foodsubcategory::model()->findAllByAttributes(array('catid' => $qryAry['id']));
$ary = array();
foreach ($qrysubcatAry as $i => $obj) {
$ary[$i]['id'] = $obj['id'];
$ary[$i]['title'] = $obj['title'];
}
echo json_encode($ary);
} else {
$ary = array();
$ary = array('status' => 'nosubcatexist');
echo json_encode($ary);
}
}
以下是描述
的图片