Mohit Chandel
Mohit Chandel

Reputation: 1916

Getting error `Uncaught TypeError: Cannot call a class as a function` while using sweet alerts 2

I am using Sweet alerts 2 in a delete function. The code is working fine, Getting the alert but when I am clicking on the delete button of the alert I am getting an error in the console. Not getting this error while clicking on the cancel button. I am using this for the first time so I don't know why I am getting this error.

Sweet Alerts 2 -> https://sweetalert2.github.io/

error ->

Uncaught TypeError: Cannot call a class as a function

My js function ->

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");
                    }
                });
            }
        });
 }

Upvotes: 1

Views: 1878

Answers (1)

Abrar Hussain
Abrar Hussain

Reputation: 21

Just Make sure anywhere else in your code you dont have a sweet alert code, i.e. Mixing swal() for Sweetalert and swal.fire() for Sweetalert2.

it will return the error you have just described.

Upvotes: 2

Related Questions