I\'m submitting a form via AJAX using the code below:
$( \'form\' ).submit(function(e) {
$.ajax({
type: \'POST\',
url: ajax_url,
Disable the submit button on the first click and re-enable it, when the AJAX call comes back.
For example:
$( 'form' ).submit(function(e) {
var $form = $(this);
$form.find('submit').attr('disabled', true);
$.ajax({
type: 'POST',
url: ajax_url,
dataType: 'json',
data: {
'action': 'my_action',
'str': $( 'form' ).serialize()
},
complete: function() {
$form.find('submit').removeAttr('disabled');
},
success: function( data ) {
// Do something here.
},
error: function( data ) {
// Do something here.
}
});
return false;
});