2014-04-01 100 views
1

我想打開幾個對話框(第一個對話框打開併發出ajax請求,如果成功顯示第二個對話框)問題是,第一個對話框打開正確在屏幕中間,但是當我關閉它時,第二個對話框在頁面頂部打開而不在中間。鏈接jquery對話框:第二個對話框不在中心

我有所有jquery ui依賴關係,因爲我使用了構建頁面並選擇了一切。

我嘗試了所有這些:123沒有成功。

該項目很大,所以我創建了一些接近我正在使用的代碼。

首先,打開對話框

$(".btblock").click(function (event) { 

    event.preventDefault(); 

    var btn = $(this); 

    var id= btn.attr('id'); 

    $("#divDialog1").dialog({ 
     dialogClass: 'notitle', 
     modal: true, 
     zIndex: 10002, 
     resizable: false, 
     closeOnEscape: false, 
     open: function (event, ui) { 
      $(".ui-dialog-titlebar-close").hide(); 
     }, 
     buttons: { 

      "Ok": function() { 
       //Here I call another function which is an ajax call. 
       //when the ajax call is completed (success or not) I call 
       //another function which creates the second dialog with results 

       $(this).dialog("close"); 
      } 
     } 
    }); 
}); 

//Function called after ajax call. creats a result dialog 
//This Dialog doesn't show in the middle of the screen 

function customAlertMessage(title, message) { 

var div = '<div style="text-align:center;" title="' + title + '">' + message + '</div>' 
$(div).dialog({ 
    resizable: false, 
    dialogClass: 'notitle', 
    modal: true, 
    buttons: { 
     "Ok": function() { 
      $(this).dialog("close"); 
     } 
    } 
}); 
} 
+0

也許你可以發佈一些代碼? – mituw16

+0

使用一些示例代碼進行編輯。 – jpgrassi

回答

0

弄成解決自己。

在我的情況下,我相信我在做錯的是我打開不同的對話框而沒有關閉以前的對話框。我做完這件事後,問題解決了。不知道爲什麼會發生這種情況。歡迎任何其他解釋或解決方案。

$(".btblock").click(function (event) { 

event.preventDefault(); 

var btn = $(this); 

var id= btn.attr('id'); 

$("#divDialog1").dialog({ 
    dialogClass: 'notitle', 
    modal: true, 
    zIndex: 10002, 
    resizable: false, 
    closeOnEscape: false, 
    open: function (event, ui) { 
     $(".ui-dialog-titlebar-close").hide(); 
    }, 
    buttons: { 

     "Ok": function() { 

      //Close First! 
      $(this).dialog("close"); 

      //Than call functions that open others dialogs     
     } 
    } 
}); 
});