如何在删除记录之前显示确认框

时间:2017-02-06 21:53:02

标签: javascript jquery ajax

我需要在执行此ajax请求之前显示一个确认框。

$(document).on("click", ".deletecustomer", function() {
    var id = $(this).attr("id");
    $.ajax({
        method: "post",
        url: "deletecustomer.php",
        data: {
            id: id
        },
        success: function(data) {
            console.log(data);
            if (data == "success") {
                window.location.href = "customer.php";
            }
        }
    });
});

1 个答案:

答案 0 :(得分:0)

$(document).on("click", ".deletecustomer", function() {
    if (confirm('Are you sure?')) {
        var id = $(this).attr("id");
        $.ajax({
            method: "post",
            url: "deletecustomer.php",
            data: {
                id: id
            },
            success: function(data) {
                console.log(data);
                if (data == "success") {
                    window.location.href = "customer.php";
                }
            }
        });
    }
});