我有swal函数的工作代码,但当我单击取消而不执行时,它将进入我不想进行的ajax调用
$(document).on('click','.addon',function() {
Swal.fire({
title: 'Provide Your Email Address',
html: `<input type="email" name="emailaddress" id="emailaddress">
`,
confirmButtonText: 'Yes',
showCancelButton:true,
focusConfirm: false,
allowOutsideClick:false,
preConfirm: () => {
const emailaddress = Swal.getPopup().querySelector('#emailaddress').value;
if (!emailIsValid(emailaddress)) {
Swal.showValidationMessage(`Please enter correct Email`)
}
return { emailaddress: emailaddress }
},
didDestroy: () => {
$(this).prop('checked',false);
return; - if i cancel, it should just quit and not go into tthen,
}
}).then((result) => {
var data = 'emailaddress=' + Swal.getPopup().querySelector('#emailaddress').value
$.ajax({
url: 'submission.cfm',
data: data,
type: 'POST',
success: function(data) {
var sdata = jQuery.parseJSON(data);
if($.trim(sdata.status) == 1) {
swal.fire({
title:"Cool",
text: sdata.message,
type:"success",
confirmButtonText: 'OK'
}).then(() => {
window.location.reload();
});
}else {
var err = sdata.message;
swal.fire("Oops...", err, "error");
}
}
});
})
});
上面的代码可以工作,但当我单击取消时,它仍然会进入ajax,但我不想让它进入那里,我错过了什么吗