ajax - Yii 如何通过 ajaxButton 发送组合的选定值?

标签 ajax yii

 echo CHtml::ajaxButton (Yii::t('Listing.Listing','Associa'), 
                    $this->createUrl('listing/addAssociation', array("id" => $model->id, "itemId"=> '5'  ) ), 
                    array('update' => '#dataToUpdate')
                    );

我正在使用此示例代码(并且它正在工作),将 id 和 itemId(示例中固定为“5”)发送到 addAssociation。

一切正常,但我需要为 itemId 传递 jQuery 表达式的结果。类似的东西

"itemId" = "js: $('#myDropDown option:selected').val();"

但在这种情况下,js 表达式不会被评估,并且在 actionAddAssociation 中我看到 itemId 是文字字符串:

 "js: $('#myDropDown option:selected').val();"

如何允许用户选择一个组合,并将所选值传递给基于此操作的操作?

最佳答案

您必须在ajax option's data property中传递它:

echo CHtml::ajaxButton (Yii::t('Listing.Listing','Associa'), 
    $this->createUrl('listing/addAssociation', array("id" => $model->id)), 
    array(// these are ajax options
        'data' => array('itemId'=> 'js: $("#myDropDown option:selected").val()'),
              // and don't use semi-colon after val(), you can also pass id here itself
        'update' => '#dataToUpdate'
    )
);

关于ajax - Yii 如何通过 ajaxButton 发送组合的选定值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13403432/

相关文章:

javascript - 结果数据的意义

javascript - HTTP 数据流

php - Yii RenderPartial 参数

php - Yii 中的数据库迁移

php - Yii2 在使用公共(public)目录运行多个应用程序时找不到文件

javascript - .post() 失败回调函数?

php - 在 Wordpress 中加载更多帖子 Ajax 按钮 - 修复

javascript - IIS PHP JavaScript HTTP 错误 414。请求 URL 太长

php - 使用 Yii session 进行负载均衡

php - 如何使用 YII 框架指定一个 SEO 友好的 url,比如 twitter www.twitter.com/<name>