【问题标题】:how to use value that i received from ajax url in yii如何使用我在 yii 中从 ajax url 收到的值
【发布时间】:2015-03-03 07:19:30
【问题描述】:

我是 yii 的新手。我有一个带有组合和文本字段的表单。现在我想通过更改组合值来更改文本字段值。 现在我通过更改组合值来获得一个 ajax url,并且 url 响应是正确的,即 10,这是我对文本字段的正确值。我的问题是我如何使用该值并将其分配给该文本字段。 我的文本字段是:

<input id="Subscription_amount" type="text" value="0" name="Subscription[amount]" >

我的控制器代码是:

public function actiongetSubAmount()
{
    $data=Subscription::model()->findByPk($_POST['sub_id']);
    echo $data->amount;
    exit(); 
}

我得到的响应 url 来自 indexController。

【问题讨论】:

  • 你能提供你的控制器的代码吗?
  • 查看我编辑的问题...

标签: php jquery ajax yii


【解决方案1】:

这个问题与php或yii无关。您需要通过 javascript 或 jquery 进行此类工作。在ajax请求的success事件中,可以这样做:

....
success: function(data){
  //data will bee everything you echo in your controller's action
  //in your case, data will be equal to $data->amount
  //if you need to pass an object or a list of object to client, you can use json_encode in your controller and $.parseJson in the view. But in your case don't need to use json, because you have only one data field. 
  $("#Subscription_amount").val(data)
},

【讨论】:

  • 但是对于 dropDownList,我们使用 $form->dropDownList($model,'id', GxHtml::listDataEx(Model_name::model( )->findAll(array('condition'=>' id='.$id)),'ai_sync_id','name'),array('prompt'=>'--SELECT--')) 并且它有效....那么在文本字段的情况下该怎么办?
  • 我认为这与这个问题无关,但是您可以使用它来生成文本字段: $form->textField($model,'fieldName',array('class'=>'className ')
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-16
相关资源
最近更新 更多