如何解决Swal2-未捕获承诺类型错误:这是未定义的
请帮我看看这个。这应该是最简单的部分,而且我已经在想它了(笑)。我就是无法确定。
Ajax 包裹在 swal 承诺中并卡在这里。取消按钮确实触发了 swal 警报,但确认按钮返回错误:
“未捕获(承诺)类型错误:这是未定义的”。
做了大量的变化,但它不会消失。 console.log(result) 显示一切正常。有人请,我没有看到和处理明显错误。
<link href="../assets/css/sweetalert2.css" rel="stylesheet" />
<script src="../assets/js/jquery-3.6.0.js"></script>
<script src="../assets/js/polyfill.js"></script>
<script src="../assets/js/sweetalert2.all.min.js"></script>
$(document).on('click','.fa-trash',function (event) {
theid = event.target.attributes['id'].value;
filename = event.target.attributes['data-filename'].value;
delrowID = event.target.attributes['data-delete'].value;
theidID = "#" + theid;
delrowID = "#" + delrowID;
$(theidID).removeClass('fa-trash')
.addClass('fa-spinner')
.addClass('fa-spin');
userID = $("#userID").val;
const swalWithBootstrapButtons = Swal.mixin({
customClass: {
confirmButton: 'btn btn-success',cancelButton: 'btn btn-danger'
},buttonsStyling: false
})
swalWithBootstrapButtons.fire({
title: 'Are you sure?',html: "You are about to <strong> delete the file " + filename + " and all its sub-files. </strong> You won't be able to revert this!",icon: 'warning',showCancelButton: true,confirmButtonText: 'Yes,delete it!',cancelButtonText: 'No,cancel!',reverseButtons: true
}).then((result) => {
console.log(result);
if (result.isConfirmed) {
$.ajax({
method: "POST",dataType: "json",url: "data_auth.php?action=delete",data: {
theid: theid,filename: filename,userID: userID
},beforeSend: function () {
Swal.fire({
title: '<strong>Please Wait...</strong>',html: '<h3>Deleting in progress</h3>',imageUrl: 'images/delete.gif',imageHeight: 200,imageAlt: 'deleting...',showCloseButton: false,showCancelButton: false,allowOutsideClick: false,allowEscapeKey: false
})
}
})
.done(function (msg) {
responsejson = JSON.parse(msg);
Swal.close();
responsejson.forEach(function (element) {
theresponse = element.response;
thedescript = element.description;
thedescriptx = element.descriptionx;
})
if (theresponse == "done") {
$(delrowID).remove();
swalWithBootstrapButtons.fire(
thedescript,'Your file (' + filename + ') has been deleted.','success'
)
return false;
}
if (theresponse == "nosuccess") {
swalWithBootstrapButtons.fire(
'Please try again!','An error occured and your file (' + filename + ') deletion was interrupted. Try Delete Again','error'
)
$(theidID).addClass('fa-trash')
.removeClass('fa-spinner')
.removeClass('fa-spin');
return false;
}
});
} else if (
result.dismiss === Swal.DismissReason.cancel
) {
swalWithBootstrapButtons.fire(
'Delete Action Cancelled','Your file (' + filename + ') is safe :)','info'
)
$(theidID).addClass('fa-trash')
.removeClass('fa-spinner')
.removeClass('fa-spin');
return false;
}
})
})
谢谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。