2010-06-01 75 views
4

我想通過ajaxStart,ajaxStop/ajaxComplete事件使用jQuery UI模式對話框作爲加載指示器。當頁面觸發時,Ajax處理程序加載一些數據,模態對話框顯示得很好。但是,當Ajax事件完成時,它永遠不會隱藏或關閉對話框。它是返回的本地服務器的一小部分代碼,因此實際的Ajax事件非常快。ajaxStart事件的jQuery模態對話框

這裏是我的模態DIV實際代碼:

 $("#modalwindow").dialog({ 
       modal: true, 
       height: 50, 
       width: 200, 
       zIndex: 999, 
       resizable: false, 
       title: "Please wait..." 
     }) 
     .bind("ajaxStart", function(){ $(this).show(); }) 
     .bind("ajaxStop", function(){ $(this).hide(); }); 

阿賈克斯事件僅僅是一個普通的$.ajax({}) GET方法調用。

基於一些在這裏搜索和谷歌,我已經嘗試改變ajaxStop處理程序使用$("#modalwindow").close(),$("#modalwindow").destroy()等(#modalwindow這裏稱爲給予明確的上下文)。

我也試過使用標準$("#modalwindow").dialog({}).ajaxStart(...以及。

我應該將事件綁定到不同的對象嗎?或者從$.ajax()完成活動中致電他們?

我應該提到,我正在測試最新的IE8,FF 3.6和Chrome。全部具有相同/相似的效果。

回答

6

找到了答案:

$("#modalwindow").dialog({ 
      modal: true, 
      height: 50, 
      width: 200, 
      zIndex: 999, 
      resizable: false, 
      title: "Please wait..." 
    }) 
    .bind("ajaxStart", function(){ 
     $(this).dialog("open"); }) 
    .bind("ajaxStop", function(){ 
     $(this).dialog("close"); 
    }); 

自我提醒:RTFM

當然,在所有這些,現在我意識到,它打開和關閉,以至於無用。哦,希望有人會覺得這有幫助。

+1

您應該將其標記爲您的問題的答案。 – ahsteele 2011-05-16 20:05:12

1

"Whenever an Ajax request completes, jQuery checks whether there are any other outstanding Ajax requests."您是否有其他AJAX請求同時運行?您需要使用ajaxComplete.ajax()的回調選項,以獲得一個完成。

+0

就是這樣;頁面中沒有其他內容了。我試着交替使用ajaxStop/ajaxComplete及其所有組合,但都沒有成功。我編輯我的問題也包括瀏覽器。 – bdl 2010-06-01 21:50:57

+0

hm。你叫'$ .ajax'的回調是否被調用? – kevingessner 2010-06-01 23:54:13

+0

是的。所有數據立即被檢索,解析並插入到DOM中。 – bdl 2010-06-02 03:52:22