1
votes

I continue getting this error when I click the close button (which doesn't close) on my JQuery Dialog:

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

in Chrome Tools after attempting a few of the suggested fixes on StackOverflow in other questions.

Can anybody point out where I am not structuring the dialog correctly to cause this error?

live fiddle here

$(document).ready(function fooDialog() {

    $('#fooChartDialog').dialog({
        autoOpen: false,
        height: 600,
        width: 1000,
        resizable: false,
        buttons: {
            "Drill Down Report": function () {
                window.open('example.com');
            },
            "Close": function () {
                $(this).dialog("close");
            }
        },
        open: function () {
            $('#fooChartDialog').load($('#fooChartDialog').data('url'), function () {
                fooChartLoad()
            });
        },
        title: 'Customer Satisfaction Chart',
        modal: true
    });

    $('#fooChartButton').click(function () {
        $('#fooChartDialog').dialog("open")
    });
});
1
you have extra commas after modal: true, "Close": function () { $('this').dialog("close"); }, - wirey00
Thanks, I removed the commas however I still have a problem when clicking the close button of the dialog not closing and throwing an error. - Alexander
@Alexander did you even find a solution to this issue? - puddinman13

1 Answers

4
votes

Try $(this).dialog("close"); instead of $('this').dialog("close");

current object should be referenced by $(this) not by $('this')