Skip to content

Instantly share code, notes, and snippets.

@yqt
Created October 13, 2013 06:36
Show Gist options
  • Save yqt/6958823 to your computer and use it in GitHub Desktop.
Save yqt/6958823 to your computer and use it in GitHub Desktop.
jQuery plugin to prevent double submission of forms
// jQuery plugin to prevent double submission of forms
jQuery.fn.preventDoubleSubmission = function() {
$(this).on('submit',function(e){
var $form = $(this);
if ($form.data('submitted') === true) {
// Previously submitted - don't submit again
e.preventDefault();
} else {
// Mark it so that the next submit can be ignored
$form.data('submitted', true);
}
});
// Keep chainability
return this;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment