【问题标题】:swal delete and cancel button both deletes the dataswal 删除和取消按钮都删除数据
【发布时间】:2019-12-18 05:40:23
【问题描述】:

我正在使用 php laravel。 我想要的是从数据表中删除记录(使用 ajax 加载),如果用户想要删除记录,他们可以单击删除按钮。 单击删除按钮后,sweetalert(swal) 与 DELETE 和 CANCEL 按钮一起使用,如下所示:

function deleteFeeds(id) {
    swal({
        title: "Are You Sure?",
        text: "",
        type: "warning",
        showCancelButton: true,
        confirmButtonClass: "btn-danger",
        confirmButtonText: "yes",
        closeOnConfirm: true,
    }).then(function (isConfirm) {
        if(isConfirm)
            {
                $.ajax({
                    headers: {  
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    },

                    url: baseUrl + 'deleteFeed/' + id,
                    method: "POST",
                    success: function (data) {
                        swal({
                            title: "deleted",
                            text: "deleted_successfully",
                            type: "success",
                            confirmButtonColor: "#00cc00",
                            confirmButtonText: "Confirm",
                        });
                        window.location.reload();

                    }
                });

            }
            else{
                swal("Cancelled", "Your feed is safe :)", "error");

            }


    });
}

但如果用户选择取消按钮,数据将被删除,这不应该发生。

谁能帮我解决这个问题?

【问题讨论】:

    标签: ajax


    【解决方案1】:

    如果条件使用isConfirm.value 而不是isConfirm

    【讨论】:

      猜你喜欢
      • 2012-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-20
      • 2018-11-25
      • 1970-01-01
      • 2012-05-23
      • 2020-03-25
      相关资源
      最近更新 更多