【问题标题】:Getting error `Uncaught TypeError: Cannot call a class as a function` while using sweet alerts 2使用甜蜜警报时出现错误“未捕获的类型错误:无法将类作为函数调用”2
【发布时间】: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


【解决方案1】:

只需确保您代码中的其他任何地方都没有甜蜜警报代码,即混合使用 Sweetalertswal()Sweetalert2swal.fire()

它会返回你刚才描述的错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-23
    • 1970-01-01
    • 2020-12-01
    • 2016-03-02
    相关资源
    最近更新 更多