Created
August 25, 2011 21:44
-
-
Save paulstefanort/1172067 to your computer and use it in GitHub Desktop.
Yii: Ajax Button: Prevent Multiple JS onclick Bindings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 */
});