2

我有一个对话框,其中包含一个名称和 ID 为“buildtask”的表单。用 Firebug 看它是完全成型的。jquery 代码与同一页面上其他成功的对话框表单提交相同。问题似乎在于,$(this).dialog("close");因为如果我将其注释掉,则调用的 ajax php 脚本可以更新数据库并回显一段我可以通过 Firebug 看到的文本。当然,对话框会留在屏幕上。

删除注释后,数据库更新失败,当发布数据显示在 Firebug 中时,响应选项卡丢失并且显示大小为 0B。

我尝试 $(this).dialog("close");在其中移动,function(data){ }但它会在屏幕上留下对话框。

我已经用问题的每个组合搜索了 Stackoverflow,但没有任何乐趣,而且我已经搞砸了六个多小时。

    buttons: {
                "Update": function() {$.post("ajax/udTManage.php", $("#buildtask").serialize(),function(data){alert("Here");});
                    $( this ).dialog( "close" );
                },
                "Cancel": function() {
                    $( this ).dialog( "close" );

                }
            },
            close: function() {
                $("#buildtask").remove();                       
                $('#tasker').submit();

            } 
4

2 回答 2

1

您应该将其$( this ).dialog( "close" );移入function(data){}以确保在完成发送请求之前不会关闭该表单。

尽管如此,由于事件是由 AJAX 调用触发的,因此 using$( this )指的是请求而不是对话框。

因此,您应该通过它的 id 调用窗口并执行以下操作:$("#buildtask").dialog("close");

然后它将起作用。

于 2013-03-11T19:18:41.217 回答
0

请注意,关闭函数中的代码将在您单击更新或取消时执行。如果您单击更新,#buildtask 将被删除并在 udTManage.php 仍在执行时提交 #tasker。

在不知道您的流程的情况下,很难确定它在哪里失败,但一种猜测是,udTManage.php 中发生的任何事情都需要在提交#tasker 之前完成。是这样吗?如果是这样,以下应该可以解决问题:

buttons: {
    "Update": function() {
        $.post(
            "ajax/udTManage.php",
            $("buildtask").serialize(),
            function(data) {
                // anything here is executed AFTER udTManage.php is executed
                $('#tasker').submit();
            }
        );
        $(this).dialog("close");
    },
    "Cancel": function() {
        $("tasker").submit(); // assuming you need to submit even when cancelling
        $(this).dialog("close");
    }
},
close: function() {
    // This is executed the moment you click either button (because both buttons immediately call the dialog close method)
    $("buildtask").remove(); // not sure why you might need this, though
}
于 2013-03-11T19:47:12.457 回答