[英]Email being sent out multiple times
我已经编写了一个JavaScript代码来处理来自联系表格的输入。 使用Ajax,我将输入信息发送到后端以发送电子邮件。
但是,似乎我的代码以某种方式发送了多封电子邮件,而不是一封。 “电子邮件已发送”消息显示了几次。
谁能告诉我出了什么问题?
JAVASCRIPT代码:
$(document).on('click', '.individual_contact', function(e) {
e.preventDefault();
var user_name = $('span#user-name').text();
var recipient_name = $(this).attr('data-ind');
console.log('recipient_name='+recipient_name);
$("div#content").hide('fast');
$("#section-form").show('fast');
$("#section-form #recipient").attr('data-contact', recipient_name);
$("#section-form #recipient").attr('placeholder', 'TO: '+recipient_name.toUpperCase());
$("#section-form #name").val('FROM: '+user_name.toUpperCase());
$('.submit_icontact').click(function(e) {
var subject = $('input#subject').val();
var message = $('textarea#message').val();
e.preventDefault();
var form = new FormData();
form.append('user_email', ajaxobject.user_id);
form.append('user_name', user_name);
form.append('recipient_name', recipient_name);
form.append('subject', subject);
form.append('message', message);
form.append('action', 'contact_individual');
console.log(form);
$.ajax({
type: 'POST',
url: ajaxobject.ajaxurl,
enctype: 'multipart/form-data',
cache: false,
contentType: false,
processData: false,
data: form,
dataType: 'json',
success: function(response) {
console.log('Email is sent');
},
error:function(err){
console.log('err,error')
}
});
});
})
每次单击.individual_contact
都会向.submit_icontact
添加另一个事件侦听.submit_icontact
。
将.submit_icontact
点击事件移出.individual_contact
点击处理程序
更改:
$('.submit_icontact').click(function(e) {
至:
$('.submit_icontact').unbind().click(function(e) {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.