2

I use my code as bellow. The function get_devcies_full is call ever 5times if the dialog opens already Don't opent it again just update the content Then i will code Bellow i the got the error in javascript

cannot call methods on dialog prior to initialization; attempted to call method isOpen

function get_devcies_full(id,slno)
{
    $.post("user/get_full_device/" +id + "/" +slno,
        function(data) {
            var NewDialog = $('<div id="MenuDialog"></div>');
            if (NewDialog.dialog( "isOpen" )!==true){
                NewDialog.dialog({
                    modal: true,
                    title: "Title",
                    width :940,
                    height:600,
                }); 
            }
            NewDialog.html(data);
            var t = setTimeout(function () {get_devcies_full(id,slno);},5000);
        }
    );
}

Please give solution where i got problem?

Rohan Kumar
  • 40,431
  • 11
  • 76
  • 106
vijaykumar
  • 4,658
  • 6
  • 37
  • 54

1 Answers1

1

Try this:

function get_devcies_full(id,slno)
{
    $.post("user/get_full_device/" +id + "/" +slno,
        function(data) {
            if(!($("#MenuDialog").length))//if this div created for first time
            {
                $(body).append('<div id="MenuDialog"></div>');//First time you have to append this in body  
            }
            if (!$('#MenuDialog').dialog('isOpen'))
            //Try if not works => if(!($("#MenuDialog").parents(".ui-dialog").is(":visible")))
            {
                $("#MenuDialog").dialog({
                    modal: true,
                    title: "Title",
                    width :940,
                    height:600    
                });
            }
            $("#MenuDialog").html(data);
            var t = setTimeout(function () {get_devcies_full(id,slno);},5000);
        }
    );
}
Rohan Kumar
  • 40,431
  • 11
  • 76
  • 106