Confirm On Ajax Request In Cgrid

Hi,

I’m trying to build in a confirmation before an ajax request is made. I’ve tried the following code, but nothing seems to happen. I don’t get the confirmation dialog and I just get passed to the controller/action.




'click'=>"function() {

	if(!confirm('Update?')) return false; 

	function(){

                                    $.fn.yiiGridView.update('grid', {

                                        type:'POST',

                                        url:$(this).attr('href'),

                                        success:function(message) {

                                              $('#Ajax-Flash').html(message).fadeIn().animate({opacity: 1.0}, 3000).fadeOut('slow');

 

                                              $.fn.yiiGridView.update('grid');

                                        }

                                    })

                                    return false;

                              } }



Where am I going wrong here? The standard ajax request works fine, I just wanted to add in a confirmation dialogue, so wrapped the ajax JS in a another function

Hi,

you can try this code


$alert_msg='Are you sure you want to delete this';


array(

            'header' => 'Action',

            'class' => 'CButtonColumn',

            'template' => {update,delete},

            'buttons' => array('delete' =>

                array(

                    'url' => 'Yii::app()->controller->createUrl("delete",array("id"=>$data->primaryKey))',

                    'label' => 'delete',

                    'options' => array(// this is the 'html' array but we specify the 'ajax' element

                        'confirm' => $alert_msg,

                        'class' => 'grid_action_set1',

                        'ajax' => array(

                            'type' => 'POST',

                            'url' => "js:$(this).attr('href')", // ajax post will use 'url' specified above

                            'success' => 'function(data){

                                                if(data == "true"){

                                                                $.fn.yiiGridView.update("liquor-category-grid");

                                                                return false;

                                                }else{

                                                                window.location="admin?del=exist";

                                                                return false;

                                                }

                                            }',

                        ),

                    ),

                ),

                'update' => array(

                    'options' => array('class' => 'grid_action_set'),

                ),

            ),

            //'buttons'=>UtilityHtml::getGridButtonAjax1($formId, $gridId, $modelName),

            'htmlOptions' => array('width' => '8%')

        ),

hope it may be helpful…

It was thank you