简体   繁体   English

弹出删除 sweetalert2

[英]pop up delete sweetalert2

i am trying to do pop up delete action with sweetalert2 in asp.net core project我正在尝试在 asp.net 核心项目中使用 sweetalert2 执行弹出删除操作

it seems delete befor the pop up it self似乎在弹出之前删除了它自己

but not working但不工作

JS:记者:

jQueryAjaxDelete = form => {
    swal({
        title: "Are you sure to delete this  of ?",
        text: "Delete Confirmation?",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Delete",
        closeOnConfirm: false
    }, function () {
        $.ajax({
            type: 'POST',
            url: form.action,
            data: new FormData(form),
            contentType: false,
            processData: false,
            success: function (res) {
                $('#view-all').html(res.html);
            },
            error: function (err) {
                console.log(err)
            }
       })
  }  ) 
};

in view在视野中

     <form asp-action="Delete" asp-route-id="@item.Id" onsubmit="return jQueryAjaxDelete(this)" class="d-inline">
                                                <input type="hidden" asp-for="@item.Id" />
                                                <input type="submit" value="Supprimer" class="btn btn-danger" />
 </form>

You need to handle the result from a promise, like this:您需要处理 promise 的结果,如下所示:

jQueryAjaxDelete = form => {
    swal({
        title: "Are you sure to delete this  of ?",
        text: "Delete Confirmation?",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Delete",
        closeOnConfirm: false
    }).then(value) => {
        // also be aware you need to check the "value" variable
        // to see if the user answered YES
        $.ajax({
            type: 'POST',
            url: form.action,
            data: new FormData(form),
            contentType: false,
            processData: false,
            success: function (res) {
                $('#view-all').html(res.html);
            },
            error: function (err) {
                console.log(err)
            }
       });
  };

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM