douzhi3779 2014-01-02 01:21
浏览 34
已采纳

Yii中CGridView上的额外Ajax

I'm quite new with Yii and I'm dealing with the CGridView which is causing me troubles.

This CGridView is in a renderPartial view.

$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'ratesGrid',
'dataProvider'=>rates::model()->searchSameProperty($propertyid),
'columns'=>array(
    'name',
    'from',
    'to',
    'price',
    array( 
    'header'=>'html',
    'type'=>'raw',
    'value'=>'\'
       <a href="#" class="deleteRate btn btn-danger" data-rateid="\'.$data->id.\'">Delete Rate</a>
       \'', 
    ),
),));

Yii::app()->clientScript->registerScript('ratesdeletion', '
$("#ratesProperty").on("click", ".deleteRate", function(e){
    e.preventDefault();
    $.ajax({
        "url":"'.CController::createUrl('rates/delete').'",

            "type":"POST",
            "data":{
                "id":$(this).data("rateid"),
            },
            "success":function(data){
                $.fn.yiiGridView.update("ratesGrid");
            },

    });
});
', CClientScript::POS_END);

The good part is when I click the delete button, it makes the call to "rates/delete" with the correct id, but when "rates/delete" finishes its work, somehow another AJAX call is made (that I've never coded), please check the screenshot.

Network tab on WebDev Tools

So my questions are:

  1. Why Yii is creating this second ajax call that I've never created?

  2. How can I avoid this second ajax call?

EDIT:

I tried adding an anchor and then attach the ajax call in a click event and it keeps making the second call.

  • 写回答

1条回答 默认 最新

  • duanhan5230 2014-01-02 13:41
    关注

    When you delete some items from a grid, first ajax call is for delete request to server and second request is for recreating the grid after your deletion. We can't avoid second ajax call while using ajax grid view like this.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集