2011-09-19 46 views
0

jquery模態對話框是異步的嗎?jquery異步對話框

$('.triage').click(function() { 

       $("#dialog-modal").dialog({ 
         position: [175, 175], 
         draggable: false, 
     height: 140, 
     modal: true 

      }); 
     }); 

     $.ajax(
       { 
       type: "POST", 
       data: [], 
       dataType: "json", 
       contentType: "application/json; charset=utf-8", 
       url: "ReferralAutoTriage.asmx/RunTriageReferrals", 
       success: function(response) { 
         $("#dialog-modal").dialog('close')        

       }, 
       failure: function(response) { 
             } 
      }); 


    }); 

如果對話框是同步的,我需要讓異步的,這樣我就可以處理Ajax調用,同時顯示對話框,靠近我用它做了。謝謝。

回答

3

使用beforeSend/complete事件來顯示/隱藏您的對話框。

$('.triage').click(function() { 
    $.ajax({ 
     type: "POST", 
     data: [], 
     dataType: "json", 
     contentType: "application/json; charset=utf-8", 
     url: "ReferralAutoTriage.asmx/RunTriageReferrals", 
     beforeSend: function() { 
      $("#dialog-modal").dialog({ 
       position: [175, 175], 
       draggable: false, 
       height: 140, 
       modal: true 
      }); 
     }, 
     success: function(response) { 
      // whatever 
     }, 
     failure: function(response) { 
      // whatever 
     }, 
     complete: function() { 
      $("#dialog-modal").dialog('close'); 
     } 
    }); 
}); 
+0

謝謝,我喜歡這個主意 – Victor

3

它認爲你的意思是「阻塞」,而不是「同步」,在這種情況下 - 不,jQuery模態對話框沒有阻塞。只有瀏覽器本機alert(),confirm()prompt()對話框可以做到這一點。

您可以絕對處理模態對話框打開的ajax調用。


這聽起來像你想弄清楚爲什麼你的代碼不工作。怎麼樣SSCCE通過http://jsfiddle.nethttp://jsbin.com

+0

感謝您的回覆。不,我沒有試圖調試代碼,仍然處於設計階段,只是對此感到好奇 – Victor