jQuery UI Dialog - Uncaught Error: cannot call methods on dialog prior to initialization; attempted to call method 'close'

StackOverflow https://stackoverflow.com/questions/23186389

문제

I have this piece of code:

function onRegisterPostSucces(data){
    $("#registerForm").dialog("close");
    $("#registerDialog").text(data);
    $("#registerDialog").dialog( "open" );

What I want to do is send register data from dialog form, and on success I want to close register dialog and open new dialog with information about creating a new account. But in line with dialog("close") I got this error:

Uncaught Error: cannot call methods on dialog prior to initialization; attempted to call method 'close' 

I tried following solutions:

$("#registerForm").dialog().dialog("close");

And

$("#registerForm").hide

But both didn't close the dialog - only hide that which was is dialog (for example inputs), dialog was still open. What I am doing wrong? Thank you in advance.

UPDATE Initialization:

$("#registerDialog").dialog({autoOpen: false});
 $("#registerBar").dialog({autoOpen: false,
            modal: true,
            width: 400, height: 600, 
            buttons: {"Zamknij": function(){
                    $(this).dialog("close");
            }}});
(...)

In #registerBar I have #registerForm:

$("#registerForm").submit(sendRegisterFormData);
function sendRegisterFormData(e){
    var contextPath='<%=request.getContextPath()%>';
    $.post(contextPath+"/login/AddUser", $("#registerForm").serialize(),
        onRegisterPostSucces);
    e.preventDefault();
}

And onRegisterPostSuccess I want to close the dialog. Button which triggered POST is not "dialog-owned" button.

도움이 되었습니까?

해결책

I do not see where you instantiated your dialog, like so (as an example):

$("#registerForm").dialog("close");

function onRegisterPostSucces(data){
    $("#registerForm").hide();
    $("#registerBar").dialog('close');
    $("#registerDialog").text(data);
    $("#registerDialog").dialog( "open" );

// this is just an an example, you probably don't need this.

 $("#registerForm").dialog({
     autoOpen: false,
     height: 300,
     width: 300,
     modal: true,
     // etc.. other things
     close: function() {
         $(this).dialog("close");
     }
   });

My guess is that you didn't instantiate it yet or the 'this' reference is not correct? Sorry if I am offbase, as I do not have eyes on the full breadth of your code.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top