jQuery帖子和对话框

时间:2012-01-31 15:42:12

标签: jquery jquery-ui jquery-dialog .post

我使用$ .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;
});

1 个答案:

答案 0 :(得分:1)

也许是因为在初始化对话框之前修改了输入?尝试在$ .post调用之前初始化它,例如:

$('#editEventContainer').dialog({
            autoOpen: false,
            width: 600,
            title: "EDIT EVENT:"
});

然后您的$ .post调用使用以下命令打开对话框:

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

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