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.

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

报告相同问题?

悬赏问题

  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码