Php yii:jqueryajax将数据添加到标签中

Php yii:jqueryajax将数据添加到标签中,php,jquery,ajax,yii,Php,Jquery,Ajax,Yii,Q:如何通过ajax将数据值添加到表的行标签中 状态:将新行添加到正在工作的窗体的表中。然后,当用户选择商品时,价格应显示在标签上(价格)。控制器返回正常。但是价格没有显示在标签上 这是我的看法 <?php $form=$this->beginWidget('CActiveForm', array( 'id'=>'acc-recei-form', 'enableAjaxValidation'=>false, )); ?> <p cla

Q:如何通过ajax将数据值添加到表的行标签中

状态:将新行添加到正在工作的窗体的表中。然后,当用户选择商品时,价格应显示在标签上(价格)。控制器返回正常。但是价格没有显示在标签上

这是我的看法

<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'acc-recei-form',
    'enableAjaxValidation'=>false,
)); ?>

    <p class="note">Fields with <span class="required">*</span> are required.</p>

    <?php echo $form->errorSummary($model); ?>
   <?php
    Yii::app()->clientScript->registerScript('add-item', "
        $('#add-item').click(function(){
            //console.log(item_template);
            $('#template .template_item').clone().appendTo('#item_list');
            $('#item_list .template_item').fadeIn();
            return false;
        });

        $('#AccRecei_acc_category_id').live('change', function(){
                                                               var itemID = $(this).val(),
                    vNode  = $(this);
                    $.ajax({
                  url: 'getitem/'+itemID,
                  dataType: 'json',
                  success: function(data){
                    var target = $(vNode).parents('tr');
                    alert(target);
                    $(target).find('.price').val(data.item_price);
                  }
                });
                //alert(vNode);
            });
");


    ?>
<table id="item_list">
<tr>
    <td>name</td>
    <td>price</td>
    <td>qty</td>
    <td>row_total</td>
<tr>
</table>
<!--- other fields -->

<div class="row buttons">
    <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
</div>

<?php $this->endWidget(); ?>

</div><!-- form -->

<table id="template" style="display:none;" >
<tr class="template_item">
    <td><?php
            echo $form->dropDownList($model,'acc_category_id', $accitemslist, array(
            'prompt'=>'Please select a category',
            'options'=>array("$model->acc_category_id"=>array('selected'=>'selected')),
            )
        ); 
        ?></td>
    <td><label id="price" class="price"></label></td>
    <td><input type="text" name="item_qty[]" class=".qty" /></td>
    <td><label id="row_total" class="row_total[]"></label></td>
<tr>
</table>

“标签”标记没有“值”。请尝试改用“”。

您好,您可以在此处使用jquery html属性。。 为标签提供一些id,然后使用下面的代码

在ajax成功消息中,添加以下内容

$(“#label_ID”).html(data.item_price)

public function actionGetitem()
    {
        echo CJSON::encode(array(
            'item_price'=>12, 
        ));
    }