Reputation: 5591
So, I have following script to handle form submission:
<script type="text/javascript" >
jQuery(document).ready(function($) {
$('body').on('click', '.rh_contact_seller_submit', function() {
if($('#rhc_email').val() === '') {
mu_form_validate($('#rhc_email'));
} else {
var data = {
'action': 'mu_send_message',
'email': $('#rhc_email').val(),
'phone': $('#rhc_phone').val(),
'message': $('#rhc_ask').val(),
'to_author': $('#rhc_author').val()
};
var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
$.post(ajaxurl, data, function(response) {
if(response === 'success'){
alert('Message Sent Successfully!');
$('.rhpm_close').click();
}
});
}
});
});
</script>
However, it often sends requests multiple times.
Is there a way for me to only send it once?
Thanks!
Upvotes: 0
Views: 53
Reputation: 2755
$('body').on('click', '.rh_contact_seller_submit', function() {
To
$('.rh_contact_seller_submit').on('click', function() {
This will work.!
Upvotes: 1