【问题标题】:jqgrid issue to refresh at close dialog windowjqgrid 问题在关闭对话框窗口时刷新
【发布时间】:2014-05-23 23:19:23
【问题描述】:

我有一个网格 (jqGrid) 我使用 ajax 调用获取数据,单击记录时会打开一个对话框窗口 (jquery ui),其中包含所选记录的详细信息。在通过另一个 ajax 调用对该记录进行更新后,关闭模式窗口并尝试通过回调 ajax 函数来更新网格来刷新网格。但是,这会导致对我的服务器的多次调用,我不知道为什么会这样,我留下我的代码,看看是否有人可以提供帮助。

$(document).ready(function () {
    ajaxCallGrid('/myjsp.jsp', 1);
});
function ajaxCallGrid (url, op) {
    $.ajax({
        url: url,
        type: "get",
        cache: false,
        beforeSend: function (xhr) {
            xhr.setRequestHeader("Content-type", "application/json; charset=ISO-8859-1");
        },
        dataType: "text json", contentType: "application/json; charset=ISO-8859-1", success: function (obj) {
            if (obj.status == "OK") {
                if (op == 1) {
                    fillJQGrid(obj.data);
                }
                else {
                    $('#list').jqGrid('clearGridData');
                    $('#list').jqGrid('setGridParam',{data: obj.problemas});
                    $('#list').trigger('reloadGrid');
                }
            }
            else alert("error-->" + url + " error-->" + obj.statustext);
        },
        error: function (jqXHR, textStatus, errorThrown) {
            alert("error-> " + errorThrown + " - " + textStatus + " -" + jqXHR.responseText);
        }
    });
}
function fillJQGrid (obj) {
    var grid = $("#list");
    grid.jqGrid({
        colModel: [{name:'XXX', index:'XXX', width:50, align:"center"},{name:'YYY', index:'YYY', width:70, hidden: true}], colNames:['X', 'Y'], pager: '#pager', datatype: "local", data: obj, rowNum: 2, viewrecords: true, caption: "DATA GRID", height: "auto", width: 1000, ignoreCase:
        true, onSelectRow: function (ids) {
            var x = $('#list').jqGrid('getRowData', ids);
            var variable = x.XXX;
            var url = '/myjsp2.jsp?variable=' + variable;
            iframe = $('<iframe frameborder="0" marginwidth="0" marginheight="0"></iframe>');
            dialog = $("<div></div>").append(iframe).appendTo("body").dialog( {
                autoOpen: false, modal: true, resizable: false, width: 1010, height: 610, closeOnEscape: true, close: function () {
                    closeIframe(1);
                    iframe.src = "about:blank";
                }
            });
            var src = url;
            var title = 'Anything';
            var width = 1010;
            var height = 610;
            iframe.attr({width: + width, height: + height, src: src});
            dialog.dialog("option", "title", title).dialog("open");
        }
    });
    grid.jqGrid('navGrid', '#pager',{edit:false, add:false, del:false});
}
function closeIframe (opt) {
    switch (opt) {
        case 1:
        dialog.dialog('close');
        break;
        case 2:
        $('<div></div>').dialog( {
            modal: true, title: "MESSAGE", open: function () {
                var markup = 'CHANFGES OK';
                $(this).html(markup);
            }, buttons: {
                ok: function () {
                    $('#list').remove();
                    $(this).dialog("close");
                }
            }, close: function () {
                dialog.dialog('destroy').remove();
                // here is when make many calls to my server....
                ajaxCallGrid('/myjsp.jsp', 2);
                /*  NEXT LINE IS BAD !!!! */
                $(this).dialog("close");
            }
        });
        break;
    }
}

myjsp2 中的下一个代码再次调用 closeIframe:

window.parent.closeIframe(2);

非常感谢。

【问题讨论】:

    标签: jquery jqgrid dialog


    【解决方案1】:

    好的,我找到了答案,我做错了事,在自身内部调用了一个关闭事件,导致了错误。我删除了那条线并完美地工作,无论如何谢谢。这里是文档:

    closing jquery modal dialog is slow

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-19
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      • 2011-05-15
      相关资源
      最近更新 更多