I\'m submitting a form via AJAX using the code below:
$( \'form\' ).submit(function(e) {
$.ajax({
type: \'POST\',
url: ajax_url,
Just add there some control variable:
var isSubmitting = false;
$( 'form' ).submit(function(e) {
if(isSubmitting) {
return;
}
isSubmitting = true;
$.ajax({
type: 'POST',
url: ajax_url,
dataType: 'json',
data: {
'action': 'my_action',
'str': $( 'form' ).serialize()
},
success: function( data ) {
isSubmitting = false;
// Do something here.
},
error: function( data ) {
isSubmitting = false;
// Do something here.
}
});
return false;
});