【发布时间】:2014-04-20 18:57:56
【问题描述】:
我有这段代码:
function onRegisterPostSucces(data){
$("#registerForm").dialog("close");
$("#registerDialog").text(data);
$("#registerDialog").dialog( "open" );
我想做的是从对话框表单发送注册数据,成功后我想关闭注册对话框并打开新对话框,其中包含有关创建新帐户的信息。 但是根据 dialog("close") 我收到了这个错误:
Uncaught Error: cannot call methods on dialog prior to initialization; attempted to call method 'close'
我尝试了以下解决方案:
$("#registerForm").dialog().dialog("close");
和
$("#registerForm").hide
但两者都没有关闭对话框 - 只隐藏对话框(例如输入),对话框仍然打开。我做错了什么?提前谢谢你。
更新初始化:
$("#registerDialog").dialog({autoOpen: false});
$("#registerBar").dialog({autoOpen: false,
modal: true,
width: 400, height: 600,
buttons: {"Zamknij": function(){
$(this).dialog("close");
}}});
(...)
在#registerBar 我有#registerForm:
$("#registerForm").submit(sendRegisterFormData);
function sendRegisterFormData(e){
var contextPath='<%=request.getContextPath()%>';
$.post(contextPath+"/login/AddUser", $("#registerForm").serialize(),
onRegisterPostSucces);
e.preventDefault();
}
而 onRegisterPostSuccess 我想关闭对话框。触发 POST 的按钮不是“对话框拥有”按钮。
【问题讨论】:
标签: javascript jquery jquery-ui dialog jquery-ui-dialog