Php CGridView更新后Ajax请求不起作用

Php CGridView更新后Ajax请求不起作用,php,jquery,yii,Php,Jquery,Yii,我想通过单击CGridView CButtonColumn view按钮打开CJuiModel,因为我的CGridView和CJuiModel如下所示:- <?php $dataProvider = new CArrayDataProvider($model->exhibitorLocation, array( 'keys' => array('productId'),

我想通过单击CGridView CButtonColumn view按钮打开CJuiModel,因为我的CGridView和CJuiModel如下所示:-

     <?php
                $dataProvider = new CArrayDataProvider($model->exhibitorLocation, array(
                    'keys' => array('productId'),
                ));


                $this->widget('zii.widgets.grid.CGridView', array(
                    'dataProvider' => $dataProvider,
                    'id' => 'exhibitor-location-grid',
                    'summaryText' => false,
                    'pager' => array(
                        'class' => 'CLinkPager',
                        'header' => false,
                    ),
                    'columns' => array(
                        array(
                            'header' => 'S No.',
                            'value' => '++$row',
                        ),
                        array(
                            'header' => 'Hall No',
                            'value' => '$data->location->hallNo',
                        ),
                        array(
                            'header' => 'Stand No',
                            'value' => '$data->standNo',
                        ),
                        array(
                            'class' => 'CButtonColumn',
                            'header' => 'Manage',
                            'template' => '{view}{delete}',
                            'buttons' => array(
                                'view' => array(
                                    'imageUrl' => $this->module->assetsUrl . "/images/info_icon.png",
                                    'options' => array('class' => 'exb-location'),
                                    'url' => 'Yii::app()->createUrl("admin/venuemap/viewExbLocation", array("exbLocId"=>$data->primaryKey))',
                                ),
                                'delete' => array(
                                    'imageUrl' => $this->module->assetsUrl . "/images/delete_icon.png",
                                    'url' => 'Yii::app()->createUrl("admin/venuemap/deleteExbLocation", array("exbLocId"=>$data->primaryKey))',
                                ),
                            ),
                            'htmlOptions' => array(
                                'style' => 'width:100px;float:center'
                            )
                        ),
                    ),
                    'rowCssClassExpression' => '($row%2 ? "visit2" : "visit1")',
                    'itemsCssClass' => 'visitor_list',
                    'htmlOptions' => array(
                    )
                ));
                ?>
                <div class="name_field">Hall No<span>*</span></div>
                <?php echo CHtml::dropDownList('hall-no', '', CHtml::listData(Venuemap::model()->findAll(), 'locationId', 'hallNo'), array('class' => 'name_input2', 'id' => 'hall-no')); ?>

                <div class="name_field">Stand No</div>
    <?php echo CHtml::textField('Stand No', '', array('class' => 'name_input', 'id' => 'stand-no')); ?> 

                <?php
                echo CHtml::ajaxLink("Add Location", Yii::app()->createUrl('admin/venuemap/addExbLocation'), array(
                    'type' => 'post',
                    'data' => array(
                        'exhibitorId' => $model->exhibitorId,
                        'standNo' => 'js: $("#stand-no").val()',
                        'locationId' => 'js: $("#hall-no").val()'
                    ),
                    'success' => 'function(html){  $.fn.yiiGridView.update("exhibitor-location-grid"); }'
                        ), array('class' => 'search_btn'));
                ?>

                 <?php
                    $this->beginWidget('zii.widgets.jui.CJuiDialog', array(
                        'id' => 'location-dialog',
                        'options' => array(
                            'title' => 'View Location',
                            'autoOpen' => false,
                            'modal' => true,
                            'width' => 'auto',
                            'height' => 'auto',
                            'resizable' => false
                        ),
                    ));
                    $this->endWidget();
                    ?>

    <?php 

    Yii::app()->clientScript->registerScript('view-location-ajax', "


    $('.exb-location').click(function(){
       url=$(this).attr('href');
       $.ajax({
       type: 'post',
       url: url,
       success: function(result){
            $('#location-dialog').html(result).dialog('open');
            $('#draggable').draggable(); 
            return false;
        }
    });
       return false;
    });


    ");
    ?>

使用JQuery“on”而不是直接事件绑定更改ajax调用:

这:

更改为:

...

$('.exb-location').on('click', '.exb-location', function(){
...

在CGridview刷新后,Html元素被销毁并重新生成。直接JQuery事件仅在DOM加载之前对现有元素起作用。删除它们或稍后添加新元素时

您必须检查数据发送的类型,如post或get,这可能是冲突。类型:“post”已在我的ClientScriptmake中提到,使其中一个从两者中获取类型可能是冲突解决冲突更改类型:“get”但不起作用仍然是相同的结果…可能使用jquery“on”而不是直接事件绑定更改ajax调用。Html元素在刷新cgridview后被销毁并重新生成,需要用jquery“on”事件引用
...

$('.exb-location').on('click', '.exb-location', function(){
...