javascript - 如何通过 ajax 将 javascript 数组传递给 YII 操作

标签 javascript ajax yii

我有一个像这样的 javascript 数组

var orderItems={'1':{id:'1',name:'Shirt',qty:'0'},'3':{id:'3',name:'Shoe',qty:'0'}, };

我需要使用 ajax 按钮将此数组传递给操作。

$this->widget('bootstrap.widgets.TbButton', array(
    'label' => 'Click me',
    'type' => 'primary',
    'htmlOptions' => array(
        'data-toggle' => 'modal',
        'data-target' => '#myModal',
        'ajax' => array(
            'type' => 'POST',
            'url' => $this->createUrl('order/AjaxUpdateOrder', 
                                      array('val' => 'profile')),
            'success' => 'function(data) { alert(data) }',
        ),
    ),
));

最佳答案

前缀“js:”到“数据”属性..如下

    'ajax' => array(
            'type' => 'POST',
            'url' => $this->createUrl('order/AjaxUpdateOrder', 
                                       array('val' => 'profile')),
            'success' => 'function(data) { alert(data) }',
            'data' => 'js:orderItems',
            'processData' => false,
    ),

关于javascript - 如何通过 ajax 将 javascript 数组传递给 YII 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12315460/

相关文章:

javascript - 我可以在 JavaScript 中全局使用导入的函数和类吗?

javascript - react .js : call a function from another component

javascript - 使用 Ember.js 获取元素数组

php - Yii CDbCommand 执行SQL语句失败 : SQLSTATE[42000]:

layout - 如何在 yii 中将数组从 Controller 发送到布局 header ?

javascript - 使用 PHP/Javascript 测试网络速度

javascript - jquery 每秒 TD 改变颜色

javascript - 在 JSONP 结果中设置 sessionStorage?

jQuery 数据表 Twitter/facebook 风格分页

php - 当 table1 中删除行时,在 table2 中插入行