【发布时间】:2016-05-12 05:16:09
【问题描述】:
我有一个页面,点击时会打开一个 jQuery 对话框。该对话框在同一域的单独页面上包含一个 iframed 表单。在父页面上,我有以下代码:
<a class="popup" href="my_form.php">Open Popup</a>
<div id="pop-content" style="display:none;">
<iframe id="pop-iframe" width="100%" height="100%"></iframe>
</div>
<script>
$(document).ready(function() {
$(".popup").click(function (e) {
// pass the url from the link to the iframe
$("#pop-iframe").attr('src', $(this).attr("href"));
// Open the dialog
$("#pop-content").dialog({
width: 850,
height: 600,
show: true,
close: function (event, ui) {
$(this).dialog('destroy');
}
});
e.preventDefault();
});
});
// Call this fucntion from the iframe after form submit
function dialogClose() {
$('#pop-content').dialog('close'); // close the iframe
window.location.reload(); // reload the parent page
return false;
};
</script>
一旦表单提交成功,我需要关闭对话框并重新加载父页面。为此,我在提交表单后使用 PHP 在页面上打印出下面的 JavaScript:
<script>
$(function () {
window.parent.parent.dialogClose();
});
</script>
但是,函数dialogClose() 没有被执行。有人可以指出我正确的方向吗?
在my_form.php 中使用它时不会出现控制台错误:
window.parent.parent.dialogClose()
当在my_form.php中使用这个时:
window.parent.dialogClose()
控制台日志:
TypeError: window.parent.dialogClose 不是函数
【问题讨论】:
-
控制台有错误吗?您是否在
my_form.php中包含 jquery 文件? -
为什么不在对话框的关闭事件中调用这个函数呢?
-
@SearchAndResQ Jquery 包含在 my_form.php 在 window.parent.parent.dialogClose() my_form.php 上使用它时,没有控制台错误,但是在使用 window.parent.dialogClose() 时控制台日志:TypeError:window.parent.dialogClose 不是函数
-
@Satyaki Chatterjee 这是我暂时要做的,但是我不想每次关闭对话框时都重新加载父级,只有在表单提交成功时才重新加载。
标签: jquery iframe dialog reload