繁体   English   中英

jQuery和Ajax删除构造框

[英]Jquery and ajax delete conformation box

我需要一个确定/取消删除确认对话框,然后再发送ajax请求才能从数据库中删除项目

var id=ID;  
$.ajax({
    type: "POST",
    url: "sample.aspx?Mode=Delete",
    data: { id: id },
    success: function (response) {                  
});

您可以简单地使用Javascript的confirm功能。 这是最简单的方法:)

var r = confirm("Are you sure you want to delete this?");
if (r == true) {
  var id=ID;  
  $.ajax({
      type: "POST",
      url: "sample.aspx?Mode=Delete",
      data: { id: id },
      success: function (response) {}             
  });
} else {
  // Do something if they push cancel button
}

您需要使用jquery UI插件。 然后,在ajax函数之前,您需要执行以下操作:

$('a.deleteBtn').on('click', function (e) {
    e.preventDefault();
    ** get you values here **

    $('div.deleteDialog').dialog({
        modal: true,
        width: 400,
        height: 'auto',
        buttons: {
            "Delete": function () {
                $(this).dialog('close');

                setTimeout(function () {
                    $.ajax({
                        method: 'POST',
                        url: url,
                        data: {****},

                        success: function () {

                        },

                        error: function () {

                    });

                }, 1000);
            },

            "Cancel": function () {
                $(this).dialog('close');
            }
        }
    });
});

在您的html文件中,您需要添加对话框

 <div class="deleteDialog" title="Package Delete Confirmation" style="display: none">
        Are you sure you want to delete this?
    </div>

暂无
暂无

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

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