Created
March 12, 2012 13:09
-
-
Save slickplaid/2021780 to your computer and use it in GitHub Desktop.
Stop double submission
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
var formSubmitted = false; | |
$(document).on('submit', '.form', function(e) { | |
if(formSubmitted) { | |
e.preventDefault(); | |
} else { | |
formSubmitted = true; | |
} | |
}); |
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
var formSubmitted = false; | |
$(document).on('click', '.info-section input[value="save"]', function(e) { | |
if(formSubmitted) { | |
e.preventDefault(); | |
} else { | |
formSubmitted = true; | |
} | |
}); |
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
$(document).on('click', 'input[type=submit]', function(e) { | |
var $this = $(this); | |
console.log('clicked'); | |
// catch ajax event, so regular input buttons still work w/o ajax | |
$(document).one('ajaxStart', function(ev) { | |
e.preventDefault(); // stop default submit action if it hasn't already been stopped | |
$this.attr('disabled', true); // disable the button | |
console.log('disabled'); | |
}); | |
$(document).one('ajaxComplete', function(ev) { | |
$this.attr('disabled', false); // re-enable the button | |
console.log('re-enabled'); | |
}); | |
}); |
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
$(document).on('click', 'input[type=submit]', function(){ | |
$(this).click(function() { | |
return false; | |
}); | |
}); |
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
(function() { | |
var submit = false; | |
$(document).on('submit', 'form', function(e) { | |
if(submit) { | |
e.preventDefault(); | |
} else { | |
submit = true; | |
} | |
}); | |
})(); |
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
$(document).on('submit', 'form', function(e) { | |
var submit = false; | |
$(this).submit(function(ev) { | |
if(submit) { | |
ev.preventDefault(); | |
} else { | |
submit = true; | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment