我在 stackoverflow 中搜索了这个问题并看到了类似的问题(但不完全是我正在寻找的问题),但该解决方案似乎不起作用。我只是 jQuery 的新手,我需要你的帮助才能完成这项工作。(交叉手指)
所以我有一个带有按钮的网页(例如 parentPage.html)。单击按钮时(执行 openItemPopup 函数),它会使用 jQuery UI 打开一个模式对话框。模态对话框“#contentWindow”的内容是不同的页面(例如modalDialog.html)。
function resetContent() {
$('#contentFrame').attr('src', '/images/ajax-loader.gif');
}
function closeContent() {
$('.ui-dialog-titlebar-close').click();
}
function openItemPopup(){
$('#contentWindow').dialog({width:980, modal: true,
close: function(ev, ui) { resetContent(); }
});
}
在modalDialog.html中,当一个锚点被点击时,它会执行一些逻辑,它需要动态关闭模态对话框。有人告诉我使用它,这已经奏效了:
// refresh parent page before closing
// doesn't work
location.reload(true);
// close the modal dialog
window.top.closeContent();
return false;
window.location='javascript:void();';
我的问题是:我需要在关闭模式对话框之前刷新 parentPage.html。您在上面看到我尝试使用 location.reload(true);,但它重新加载模式对话框而不是 parentPage.html。我无法发布图片,但它显示 * "Invalid Web application session"。*
我也试过 window.top.location.reload(); 它似乎工作。它重新加载 parentPage.html 并关闭模式对话框。
// refresh parent page before closing
// seems working but has error
window.top.location.reload();
// close the modal dialog
window.top.closeContent();
return false;
window.location='javascript:void();';
但是,它显示“无效的 Web 应用程序会话”。-- 就像使用 location.reload(true); 时一样。我不知道为什么会发生这种情况以及如何解决它。我什至不确定 window.top.location.reload 是否是正确的方法。
仅供参考:我正在尝试刷新 parentPage.html 以便能够从模式对话框中获取数据。之前,modalDialog.html 用作简单的 html 页面。列表和字段等数据从 modalDialog.html 正确返回到 parentPage.html。他们想将其转换为模式对话框以防止大量页面刷新。有人告诉我可以使用 AJAX,但工作量很大。此外,我不是它的主人。如果您有更好的建议,请随时告诉我!
我希望你能帮助我解决这个问题。提前致谢!!!