我有一个网格(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);
非常感谢。
答案 0 :(得分:0)
好的,我找到了答案,我做了一些不好的事情,在自己内部调用一个关闭事件来制造错误。我删除那条线并完美地工作,无论如何,谢谢。这里的文档: