jQuery发布和对话框

jQuery发布和对话框,jquery,jquery-ui,jquery-dialog,.post,Jquery,Jquery Ui,Jquery Dialog,.post,我使用$.post()从数据库中检索内容,然后我想用它来操作表单值。完成后,我希望jQuery对话框打开。这是一个非常简单的“编辑事件”系统,我写的。我只是无法在$.post()中打开对话框,如果在$.post()之外打开对话框,表单值将返回空值 我理解这样的概念,即它不会工作,因为无论回调是否成功,脚本都会继续运行,但是有其他方法可以做到这一点吗 我的代码: // Edit a banner: $("input[name='eventEditBtn']").click(function() {

我使用$.post()从数据库中检索内容,然后我想用它来操作表单值。完成后,我希望jQuery对话框打开。这是一个非常简单的“编辑事件”系统,我写的。我只是无法在$.post()中打开对话框,如果在$.post()之外打开对话框,表单值将返回空值

我理解这样的概念,即它不会工作,因为无论回调是否成功,脚本都会继续运行,但是有其他方法可以做到这一点吗

我的代码:

// Edit a banner:
$("input[name='eventEditBtn']").click(function() {
    var eventID = $(this).attr("rel");
    $.post("www/scripts/ajax/getEventInfo.php",{id : eventID},function(data) {
        if(data.success == true) {
            var info = data.info;
            $("input[name='editEventName']").val(info.name);
            $("input[name='editEventDate']").val(info.date);
            $("input[name='editEventTime']").val(info.time);
            $("textarea[name='editEventSummary']").val(info.summary);
            $("textarea[name='editEventDescription']").val(info.description);
            $("#editEventCurrentCategory").html("The current category is: "+info.categoryName);
            $("input[name='editEventVenue']").val(info.venue);
            $("input[name='editEventCost']").val(info.cost);
            $("#editEventCurrentStatus").html("The current status is: "+info.categoryName);
            $("#editEventContainer").dialog({width: 600, title: "EDIT EVENT:"});
        } else {
            $("<div />").dialog("An error has occured retrieving this event information.");
            return false;
        }
    });
    return false;
});
//编辑横幅:
$(“输入[name='eventEditBtn'])。单击(函数(){
var eventID=$(this.attr(“rel”);
$.post(“www/scripts/ajax/getEventInfo.php”,{id:eventID},函数(数据){
if(data.success==true){
var info=data.info;
$(“输入[name='editEventName']”)val(info.name);
$(“输入[name='editEventDate']”)val(info.date);
$(“输入[name='editEventTime']”)val(info.time);
$(“textarea[name='editEventSummary']”)val(info.summary);
$(“textarea[name='editEventDescription']”)val(info.description);
$(“#editEventCurrentCategory”).html(“当前类别为:“+info.categoryName”);
$(“输入[name='editEventVincement']”)val(info.venture);
$(“输入[name='editEventCost']”)val(info.cost);
$(“#editEventCurrentStatus”).html(“当前状态为:“+info.categoryName”);
$(“#editEventContainer”)。对话框({宽度:600,标题:“编辑事件:”});
}否则{
$(“”)。对话框(“检索此事件信息时出错。”);
返回false;
}
});
返回false;
});

可能是因为在初始化对话框之前修改了输入?尝试在$.post调用之前对其进行初始化,如下所示,例如:

$('#editEventContainer').dialog({
            autoOpen: false,
            width: 600,
            title: "EDIT EVENT:"
});
然后,您的$.post调用将使用以下命令打开对话框:

$('#editEventContainer').dialog('open');

还记得检查选择器是否正确。

控制台中是否有错误?有几个选择。在打开对话框之前设置一个短暂的超时,或者更早地实例化对话框并隐藏/关闭它,然后在当前实例化它的位置打开它。