我有一個按鈕,觸發一個彈出如下。我從服務器端拉出一些信息,將其顯示在彈出窗口中。問題是需要一段時間才能拉起服務器端的信息,我的對話框會打開爲空,然後在1-2秒後顯示信息。它很煩人。只有當服務器端信息準備就緒時,纔有辦法顯示對話框?如何在打開事件之前隱藏jquery對話框?
function openPopup(id)
{
$("#divPopup").dialog({
resizable: true,
height: 200,
width: 300,
modal: true,
title: 'Popup Title',
buttons: {
OK: function() {
//TODO
$(this).dialog("close");
},
Cancel: function() {
$(this).dialog("close");
}
},
open: function (event, ui) {
// Can I hide the dialog popup before the info is ready?
populateInfo(id);
addDialogBGConfirm($(this).parent().css('z-index') - 1);
},
close: function (event, ui) {
removeDialogBGConfirm();
}
});
}
function populateInfo(id)
{
$.ajax({
type: 'POST',
contentType: 'application/json; charset=utf-8',
url: window.location.href + "/GetServerSideInfo",
data: "{'profileId': '" + id + "'}",
dataType: 'json',
success: function (res) {
// populate popup controls based on server side info
$('.pname').text(res.d[0]);
// ...
},
error: function (data, textStatus) {
alert('Error in calling method');
}
});
}
顯示加載動畫裏面彈出是更好的方法,你問什麼可以鼓勵用戶點擊兩次按鈕打開彈出窗口(假設點擊某個按鈕後打開)。 – yogi
謝謝!但是我想在服務器端信息準備好之前隱藏所有的控件。我試圖把一個顯示器:在開放的第一行沒有css,但它似乎並沒有工作... – Deceleven
如何在ajax完成後打開對話框? P.S我實際上支持@yogi的解決方案 –