【发布时间】:2021-02-16 06:27:33
【问题描述】:
html 页面上有一个取消按钮。当我单击该按钮时,会弹出带有确定和取消选项的警报以及右上角的十字按钮。因此,当我单击 Ok 按钮时,会触发 AJAX 事件,但问题是当我单击取消或单击交叉按钮时,还会触发 AJAX 事件的警报,而这是不应该的。 代码如下:
我不想在单击取消或十字按钮时调用 AJAX。 我该怎么办?
$("#cancelButton").click(function(){
Swal.fire({
title: "We are sad to see you go! ????",
text: "Do you really want to unsubscribe?",
icon: "warning",
showCloseButton: true,
button: "Ok",
showCancelButton: true
}).then((result) => {
$.LoadingOverlay("show");
$.ajax({
type: "GET",
url: "/v1/subscriptions/{{user.subsID}}",
dataType: "json",
contentType: "application/json",
success: function(response){
if (response.status == '200') {
$.LoadingOverlay("hide");
Swal.fire({
title: "Cancelled",
text: "You have been unsubscribed and will no longer hear from us after the end of the current month subscription! ☹️",
icon: "success",
button: "Ok",
showCancelButton: true
}).then((result) => {
if (result) {
window.location.reload();
}
});
}
else if (response.status == '500') {
$.LoadingOverlay("hide");
Swal.fire({
title: "Error",
text: "Subscription has already been cancelled",
icon: "error",
button: "Ok",
showCancelButton: true
})
}
}
});
})
});
【问题讨论】:
标签: javascript jquery ajax sweetalert2