0

我有一个$_POST指向同一页面的删除输入按钮。我有一个 jquery 确认模式,当它被点击时会弹出。如果是,则发布表单,如果不是,则取消该操作。

<?php
    if ($_POST['doDelete'] == 'Delete') {
        if (!empty($_POST['u'])) {
            foreach ($_POST['u'] as $uid) {
                $id = filter($uid);
                if (deleteRecord('projects', $id, false)) {
                    $fail[] = $id;
                } else {
                    $pass[] = $id;
                }
            }
        }
        $msg = new Messages();
        if (!empty($pass)) {
            $passed = implode(', ', $pass);
            $message = "Deleted: {$passed}";
            $msg->add('s', $message);
        }
        if(!empty($fail)){
            $failure = implode(', ', $fail);
            $message = "Could not delete/an error occured: {$failure}";
            $msg->add('e', $message);
        }
        redirect('projects.php');
    }
?>
<script>
    $(function () {
        $("#dialog-confirm-multiple").dialog({
            autoOpen: false,
            resizable: false,
            width: 300,
            modal: true,
            show: {
                effect: "bounce",
                duration: 100
            },
            hide: "drop",
            buttons: {
                "Yes": function () {
                    $("#confirm").submit();
                },
                "No": function () {
                    $(this).dialog("close");
                }
            }
        });
        $("#doDelete").click(function (e) {
            e.preventDefault();
            $("#dialog-confirm-multiple").dialog('open');
            return false;
        });
    });
</script>
<form post="self.php" id="confirm">
<!-- some inputs .etc -->
<input name="doDelete" type="submit" id="doDelete" value="Delete" class="btn btn-danger">
</form>

按钮 id 是doDelete,表单 id 是confirm。然而,模式仅在用户单击yes而不发布表单后自行关闭。当我注释掉这段代码时,按钮工作正常,并删除记录(帖子成功)。

类似于:jquery 对话框:确认点击提交按钮

4

2 回答 2

0

亚历克斯:

尝试按以下方式进行 ajax 调用:

$.ajax({
        type: "POST",
        url: "YOUR_PHP_URL",
        data: "YOUR_VARIABLE",
        async: false,
        beforeSend: function () { /// use beforeSend to open a dialog box 

        $("#dialog-confirm-multiple").dialog({
          //...

        });


        },
        success: function (response) {
            //the dialog will just load but the form will still continue to submit                             
        }

    });

当你使用“beforeSend”功能时,魔法就来了……我希望我能帮助你……

于 2013-07-04T17:50:41.577 回答
0

您是否尝试在关闭对话框之前发送表单?

$("#dialog-confirm-multiple").dialog({
    buttons: {
        "Yes": function () {
            $("#confirm").submit();
            $(this).dialog("close");
        },
        "No": function () {
            $(this).dialog("close");
        }
    }
});
于 2013-07-04T18:36:52.560 回答