2013-03-07 63 views
0

我有一個對話框彈出窗口,它使用YUI庫發佈表單並且目前爲止工作正常。但是如何在表單提交成功後再調用另一個函數。我基本上需要從數據庫表格行中抽取一個字段,這個表格是由表單提交創建的。YUI對話框,表單提交成功後的回調

這是到目前爲止我的代碼:

var callback = { 

    success: function(result) { 

     form = result.responseText; 

     dialog = new YAHOO.widget.Dialog('dialog1', { 
      width: '400px', 

      fixedcenter : "contained", 
      visible : false, 
      draggable: true, 
      effect:[{effect:YAHOO.widget.ContainerEffect.SLIDE, duration:0.2}, 
        {effect:YAHOO.widget.ContainerEffect.FADE,duration:0.2}], 
      modal:true 
     }); 

     dialog.setHeader(titleval); 
     dialog.setBody(form); 

     var handleCancel = function() { 
      this.cancel(); 

     }; 
     var handleSubmit = function() { 

      date_box = dialog.getData().date; 
      reason_box = dialog.getData().reason; 
      hours = dialog.getData().date_start_hours; 
      mins = dialog.getData().date_start_minutes; 
      format = dialog.getData().format; 
      ampm = dialog.getData().date_start_meridiem; 
      username = dialog.getData().user; 

      //basic validation 
      if(date_box == '' && reason_box == ''){ 

       document.getElementById('error1').style.display = ""; 
       document.getElementById('error2').style.display = ""; 

      }else if(date_box == '' || !isDate(date_box)){ 

       document.getElementById('error1').style.display = ""; 
       document.getElementById('error2').style.display = "none"; 

      } 
      else if(reason_box == '' && !isDate(date_box)){ 

       document.getElementById('error1').style.display = ""; 
       document.getElementById('error2').style.display = ""; 

      } 
      else if(reason_box == ''){ 

       document.getElementById('error1').style.display = "none"; 
       document.getElementById('error2').style.display = ""; 

      } 
      else{ 

       this.submit(); 
       update(date_box, hours, mins, format, ampm, reason_box, username); 
      } 

     }; 
     var myButtons = [{ text: "Save", handler: handleSubmit, isDefault: true }, 
         { text: "Cancel", handler:handleCancel }]; 

     dialog.cfg.queueProperty("buttons", myButtons); 
     dialog.render(document.body); 
     dialog.show(); 

     document.getElementById('call_id').value = id.value; 
     eval(document.getElementById('script').innerHTML); 
     eval(document.getElementById('script2').innerHTML); 

    } 

} 

var connectionObject = YAHOO.util.Connect.asyncRequest ("GET", "index.php?entryPoint=Reschedule&call_id="+id.value, callback); 

回答

0

我認爲此頁面包含了答案:http://developer.yahoo.com/yui/container/dialog/

向下滾動到標題爲「提交表​​單數據」一節。它顯示瞭如何配置回調。

+0

我看到了,但我不知道如何將其添加到我的代碼,因爲它在哪裏去 – user794846 2013-03-08 14:11:06

+0

在dialog.setBody(form)之後,添加一行myDialog.callback.success = onSuccess,其中onSuccess是您的回調函數。同樣對於myDialog.callback.failure – 2013-03-11 18:10:25