Skip to content

Instantly share code, notes, and snippets.

@paulstefanort
Created August 25, 2011 21:44
Show Gist options
  • Save paulstefanort/1172067 to your computer and use it in GitHub Desktop.
Save paulstefanort/1172067 to your computer and use it in GitHub Desktop.
Yii: Ajax Button: Prevent Multiple JS onclick Bindings
<?php
/* From http://stackoverflow.com/questions/5039494/yii-ajax-button-how-to-prevent-multiple-js-onclick-bindings */
echo CHtml::submitButton($diary->isNewRecord ? 'Создать' : 'Сохранить', array('id' => 'newRecSubmit'));
Yii::app()->clientScript->registerScript('btnNewRec', "
var clickNewRec = function()
{
jQuery.ajax({
'success': function(data) {
$('#ui-tabs-1').empty();
$('#ui-tabs-1').append(data);
},
'type': 'POST',
'url': '".$this->createUrl('/diary/newRecord')."',
'cache': false,
'data': jQuery(this).parents('form').serialize()
});
$('#new-rec-form').unbind();
return false;
}
$('#newRecSubmit').unbind('click').click(clickNewRec);
");
@paulstefanort
Copy link
Author

Originally from http://stackoverflow.com/questions/5039494/yii-ajax-button-how-to-prevent-multiple-js-onclick-bindings.

Primary feature:
$('#InterfaceComponent').unbind('click').click(function() {
/* function to execute */
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment