2012-03-30 27 views
1

在下面的對話形式,我有2個按鈕:保存&取消。當用戶雙擊保存按鈕時,我的數據被張貼2次。我怎樣才能避免它?我的數據發佈2次在我的jQuery的對話框

$(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(); } 
      } 
     }); 

謝謝。

回答

0

這是一個老問題。有一件事你可以做的是

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(); } 
     } 
    }); 
+0

謝謝尼古拉。 – Bronzato 2012-03-30 09:17:21

相關問題