为了防止出现两次错误,我使用了“发送前”的代码:
hasSent = false
function submit() {
if (!hasSent)
$.ajax({
url: "${createLink(controller:'userInvitation', action:'ajaxUpdate')}",
type: "POST",
data: $("#invitationForm").serialize(),
success: function(data, textStatus, jqXHR) {
$('#invitationForm')[0].reset();
$('.thank-you-modal').modal('show');
hasSent = true;
console.log(hasSent)
},
complete: function() {
hasSent = false;
console.log(hasSent)
}
});
}
如你所见,只有当hassent=false时,Ajax才会发生。由于某些原因,如果用户在Submit按钮上单击多次(非常快),Ajax也会发生。