0

我在 jQuery 对话中加载 html 页面,但是当我使用关闭按钮关闭对话并再次打开对话时,它会给出以下错误:

Error: cannot call methods on dialogue prior to initialization; attempted to call method 'isOpen'

我的代码

$("#enterRunnerPositionDialog").dialog({
    autoOpen: false,
    position: 'center',
    title: 'Enter Runner Position Selection',
    draggable: false,
    width: 1000,
    height: 900,
    resizable: false,
    modal: true,
    open: function (event, ui) {
        var html = "";
        $.ajax({
            type: "GET",
            url: "AdminController",
            data: {
                overlayScreenNo: 25,
                objectName: 'horseNo'
            },
            success: function (response) {
                var parseJSON = eval('(' + response + ')');
                var success = parseJSON.success;
                var status = parseJSON.status;
                if (success == true && status == 200) {
                    displayRunner(parseJSON.result);
                } else {
                    //alert(parseJSON.msg);
                }
            }
        });
    }

    $("#enterRunnerPositionButton").click(function () {
        $("#enterRunnerPositionDialog").load('runnerPositionSelection.html', function () {
            //$("#enterRunnerPositionDialog").dialog("open");
        });
        if ($("#enterRunnerPositionDialog").dialog("isOpen")) {} else $("#enterRunnerPositionDialog").dialog("open");
    });
4

1 回答 1

0

好吧,我希望我有 HTML 并可以访问 AJAX 页面,但是因为我没有,所以您必须对此进行测试并给我反馈。代码中有很多错误,在下面修复。缺少括号,对象被调用太多次(可能是您得到错误的来源)等。

尝试这个:

$dlg = $("#enterRunnerPositionDialog");
$btn = $("#enterRunnerPositionButton");
$dlg.dialog({
    autoOpen: false,
    position: 'center',
    title: 'Enter Runner Position Selection',
    draggable: false,
    width: 1000,
    height: 900,
    resizable: false,
    modal: true,
    open: function (event, ui) {
        var html = "";
        $.ajax({
            type: "GET",
            url: "AdminController",
            data: {
                overlayScreenNo: 25,
                objectName: 'horseNo'
            },
            success: function (response) {
                var parseJSON = eval('(' + response + ')');
                var success = parseJSON.success;
                var status = parseJSON.status;
                if (success === true && status === 200) {
                    displayRunner(parseJSON.result);
                } else {
                    //alert(parseJSON.msg);
                }
            }
        });
    }
});
$btn.click(function () {
    //$("#enterRunnerPositionDialog").load('runnerPositionSelection.html', function () {
    //$("#enterRunnerPositionDialog").dialog("open");
    //});
    if ($dlg.dialog("isOpen")) {
        return;
    } else {
        $dlg.dialog("open");
    }
});
于 2013-10-26T15:03:39.023 回答