Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我的数据在我的jQuery对话框上发布了两次_Jquery_Jquery Ui - Fatal编程技术网

我的数据在我的jQuery对话框上发布了两次

我的数据在我的jQuery对话框上发布了两次,jquery,jquery-ui,Jquery,Jquery Ui,在下面的对话框窗体中,我有两个按钮:保存和取消。当用户双击“保存”按钮时,我的数据将被发布2次。我怎样才能避免呢 $(this).dialog({ modal: true, resizable: false, title: "Edit", close: function () { $(this).dialog('destroy').remove(); }, buttons: {

在下面的对话框窗体中,我有两个按钮:保存和取消。当用户双击“保存”按钮时,我的数据将被发布2次。我怎样才能避免呢

$(this).dialog({
            modal: true,
            resizable: false,
            title: "Edit",
            close: function () { $(this).dialog('destroy').remove(); },
            buttons: {
                "Save": function () {
                    // Manually submit the form
                    var form = $('form', this);
                    $(form).submit();                        
                },
                "Cancel": function () { $(this).dialog('destroy').remove(); }
            }
        });

谢谢。

这是个老问题。你可以做的一件事是

var submitted = false;
$(this).dialog({
        modal: true,
        resizable: false,
        title: "Edit",
        close: function () { $(this).dialog('destroy').remove(); },
        buttons: {
            "Save": function () {
                // Manually submit the form
                if(!submitted){
                    submitted = true;
                    var form = $('form', this);
                    $(form).submit();                        
                }
            },
            "Cancel": function () { $(this).dialog('destroy').remove(); }
        }
    });