在表单提交上关闭jQuery模式对话框

时间:2011-09-21 04:35:49

标签: jquery

我有一个有形式的模态对话框。当用户单击对话框上的提交按钮时,我希望提交表单,并且工作正常。我正在使用ajax请求,因此在提交中使用 return false; 。这是我的代码:

    $("#new_account_class").live("submit", function(){
        $.post(this.action, $(this).serialize(), null, "script");
        return false;
    });

现在,我希望在同一事件中关闭对话框。问题是,在返回false; 之后我写的任何内容都没有执行,我无法在返回false 之前关闭对话框。但是必须有出路,有人可以帮忙吗?感谢。

2 个答案:

答案 0 :(得分:1)

你不能在'$ .post之后添加代码(...'?示例:

$("#new_account_class").live("submit", function(){
    $.post(this.action, $(this).serialize(), null, "script");
    myModal.close(); //example code
    return false;
});

答案 1 :(得分:1)

$("#new_account_class").live("submit", function(){
    $.post(this.action, $(this).serialize(), function(){
     //this callback is executed upon success full form submission close modal here

  }, "script");
    return false;
});
相关问题