t4t5 / sweetalert

A beautiful replacement for JavaScript's "alert"
https://sweetalert.js.org
MIT License
22.4k stars 2.85k forks source link

Submit button brings sweetalert popup without saving data in the database #1003

Open Emmanuelf7 opened 1 year ago

Emmanuelf7 commented 1 year ago

function saveCategory() {

        var category = new Object();
        category.CategoryId = $("#categoryId").val();
        category.CategoryName = $("#categoryName").val();
        category.Status = $("#status").val();
        var data = JSON.stringify({
            category: category
        });

        document.getElementById('success-message').onclick = function () {
            swal('Success!', 'Category is Saved!', 'success')
        };
        swal({              

                Position:'top-end',
                icon: "success",
                title: 'Your work has been saved',
                showConfirmButton: false,
                timer:1500

        }).then(function (isConfirm) {
            if (isConfirm) {

                return $.ajax({
                    contentType: 'application/json; charset=ut-8',
                    dataType: 'json',
                    type: 'POST',
                    url: "/Home/SaveCategory",
                    data: data,
                    success: function (result) {
                        if (result == true) {
                            GetAllCategory();
                            dataTable.ajax.reload();

                        }
                    }
                });
            } else {

                swal("Cancelled", "You have Cancelled Form Submission!", "error");
                $("#categoryModal").modal('hide');

            }

        });

    }