无法在jquery中触发Ajax代码

时间:2015-06-15 07:25:48

标签: javascript jquery ajax

我正在使用sweatalert UI作为我的提示消息进行确认。在我的jQuery中,我有一个Ajax代码,当用户点击“是,删除它”时删除该项目。

但我不确定为什么我的Ajax代码无法触发。我有错误的代码吗?请指出给我。感谢

以下是按钮的html代码:

<form id="packageRemove" class="packageRemove" name="packageRemove">
    <input type="hidden" id="pRemove" name="pRemove" class="pRemove" value="1">
        <button style="left:-35px;" class="btn btn-primary pull-right warning-message-parameter">X</button>
</form>

这是我用来触发ajax代码的ui-notification.js代码:

$(".warning-message-parameter").on("click", function(e) {
            swal({
                title: "Are you sure?",
                text: "You will not be able to recover this directory file!",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "Yes, delete it!",
                cancelButtonText: "No, cancel plx!",
                closeOnConfirm: false,
                closeOnCancel: false
            }, function(isConfirm) {
                if(isConfirm) {
                    $.ajax({
                            url: 'packageDelete.php',
                            data: el.closest('packageRemove').serialize(),
                            type: 'post',   
                            success: function(){
                                swal("Deleted!", "Your directory file has been deleted.", "success");
                            }
                    });
                } else {
                    swal("Cancelled", "Your directory file is safe :)", "error");
                }
            });

            e.preventDefault();
        });

1 个答案:

答案 0 :(得分:0)

您的变量 el 未定义,因为您将变量命名为 e

("click", function(e) {

更改为

("click", function(el) {