Problem Blocking Multiple Clicks On Button With Ajax

I have a button in a CButtonColumn that fires an ajax request. If the user clicks on it multiple times it generates multiple requests, something I don’t want to happen. I’ve tried disabling the anchor tag in the onclick handler, and in the beforeSend option in the ajax criteria, but without success. The functions fire, but subsequent clicks still fire the ajax request.

Some of the attempts I have tried in the onclick and beforeSend options are:




this.attr("href")="";


this.disabled=true;


js:$(this).attr("disabled")="disabled";


if($(this).attr("disabled") == "disabled") {return false} else {$(this).attr("disabled") = "disabled"}


if (js:$(this).attr("disabled") == "disabled") {return false} else {js:$(this).attr("disabled") = "disabled"}




Does anyone have any ideas?

Here is the code for the CButtonColumn:




'buttons'=>array(

          'endPeriod'=>array('imageUrl'=>Yii::app()->request->baseUrl.'/images/calendar_view_day.png',

                             'url'=>'Yii::app()->createUrl("user/endPeriod", array("id"=>$data->id, "userId"=>$data->user_id ))',

                             'options'=>array('title'=>'End current period and create new period',

                                              'ajax'=>array('type'=>'get',

                                                            'url'=>'js:$(this).attr("href")',

                                                            'success' => 'js:function(data) { reloadGrids(data);}'

                                                           ),

                                             ),

                            ),

                ),



Thanks in advance

Hi,

I have different IDEA

Use this plugin… it wont allow user to more click…

http://malsup.com/jquery/block/

Here is the code for the CButtonColumn:




'buttons'=>array(

          'endPeriod'=>array('imageUrl'=>Yii::app()->request->baseUrl.'/images/calendar_view_day.png',

                     		'url'=>'Yii::app()->createUrl("user/endPeriod", array("id"=>$data->id, "userId"=>$data->user_id ))',

                     		'options'=>array('title'=>'End current period and create new period',

                                              'ajax'=>array('type'=>'get',

                                                            'url'=>'js:$(this).attr("href")',


						       'beforeSend' => "function(request)

		     			       {

		     		          	$.blockUI();

		     			       }",

                                                          'success' => 'js:function(data) { reloadGrids(data);}'


						  	'complete' => "function(request)

		     			  	{

		       					$.unblockUI();

		     			  	}",

                                                   		),

                                     		),

                            ),

                ),