简体   繁体   中英

How to pass javascript array to and YII action through ajax

I'm having a javascript array like

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

I need to pass this array to an action using a ajax button.

$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) }',
        ),
    ),
));

prefix 'js:' to 'data' attribute .. like below

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM