【发布时间】:2020-12-10 05:46:18
【问题描述】:
我在删除功能中使用 Sweet alerts 2。代码工作正常,获取警报,但是当我单击警报的删除按钮时,我在控制台中收到错误消息。单击取消按钮时未收到此错误。我是第一次使用,所以不知道为什么会出现这个错误。
甜蜜警报 2 -> https://sweetalert2.github.io/
错误->
未捕获的类型错误:无法将类作为函数调用
我的js函数->
function onDelete(){
swal.fire({
title: 'Are you sure?',
text: "You won't be able to revert this!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then((result) => {
if (result.isConfirmed) {
jQuery.ajax({
url: "url",
type: "POST",
data: {
id: 2
},
success: function () {
swal.fire("Done!", "It was succesfully deleted!", "success");
},
error: function () {
swal.fire("Error deleting!", "Please try again", "error");
}
});
}
});
}
【问题讨论】:
-
你的代码看起来不错,你确定错误是这个函数引起的吗?
-
@YorkChen 我只在这个函数中使用了甜蜜警报
-
在控制台点击错误可以看到是哪一行代码出错了。
标签: javascript sweetalert sweetalert2