Yii Ajax Update取决于下拉选择

时间:2013-11-24 05:34:06

标签: php ajax yii

我有下拉列表,其中有五到六个项目(这里的项目是服务)。我在这里使用ajax请求,一旦我选择任何服务项,就会从URL 'url'=>$this->createUrl('servicePackage'),更新id“package_id”。直到现在,我已经成功完成了。但是我希望ajax应该使用不同的URL并更新不同的id,即如果我选择第4个数字项则“registrationid”,否则它应该更新“package_id”。 有可能吗?

有可能吗?

表格是:

<div class="form-group">
    <?php echo $form->labelEx($model,'service_id', array('class' => 'control-label col-lg-4')); ?>
    <div class="col-lg-8">
    <?php echo $form->dropDownList($model,'service_id',CHtml::listData(Service::model()->findAll(),'id', 'name'),
    array(
        'class' => 'form-control',
        'prompt'=>'Select a Service',
        'ajax' => array('type'=>'POST',
            'url'=>$this->createUrl('servicePackage'), 
            'update'=>'#'.CHtml::activeId($model, 'package_id'), // ajax updates package_id, but I want ajax update registration_id if I select item no 4
            'data'=>array('service_id'=>'js:this.value'),
        )));
    ?>
    </div>
    <?php echo $form->error($model,'service_id'); ?>
</div>

<div class="form-group" id="packageid">
    <?php echo $form->labelEx($model,'package_id', array('class' => 'control-label col-lg-4')); ?>
    <div class="col-lg-8">
    <?php
    echo $form->dropDownList($model,'package_id',$model->getServicePackage($model->service_id),array(
        'class' => 'form-control','prompt'=>'Select a Package',
        'ajax' =>
        array('type'=>'POST',
            'url'=>$this->createUrl('packagePrice'), //url to call.
            'update'=>'#price', //selector to update
            'data'=>array('package_id'=>'js:this.value'),
        )));
    ?>
    </div>
    <?php echo $form->error($model,'package_id'); ?>
</div>

<div class="form-group" id="registrationid">
    <?php echo $form->labelEx($model,'registration_id', array('class' => 'control-label col-lg-4')); ?>
    <div class="col-lg-8">
        <?php
        $registrants = Registration::model()->findAll();
        $data = CHtml::listData($registrants,'id', function($registrants) {
            return CHtml::encode($registrants->name.' ('.$registrants->id.')');
        });
        echo $form->dropDownList($model,'registration_id',$data,
            array(
                'class' => 'required form-control chzn-select',
                'prompt'=>'Select a Registrant',
                'ajax' => array('type'=>'POST',
                    'url'=>$this->createUrl('Order'), //url to call.
                    'update'=>'#'.CHtml::activeId($model, 'order_id'), //selector to update
                    'data'=>array('registration_id'=>'js:this.value'),
                )

            ));
        ?>
    </div>
    <?php echo $form->error($model,'registration_id'); ?>
</div>

0 个答案:

没有答案