0

所以我的网站上有几个模态窗口。我通常使用 jquery 和 ajax 在模态窗口中完成一些事情并更新父页面上的 div。

我的问题是我正在上传文件,所以我不得不使用我从未使用过的 iframe,而我使用的是 javascript,而不是我从未使用过的 jquery,所以我有点迷茫并寻找方向。

我正在尝试从我的模式窗口更新父页面上的 div。在模态窗口中,我有一个针对 iframe 的表单,并且该操作针对单独的 php 页面。总体问题是如何在表单上传文件后将更新的 $attachment_table 发送到父 div?我正在努力:

Modal_window.php - 上面有一个上传文件的表单。

<?php
$attachment_table = '';
while (($row73 = $answer17->fetch(PDO::FETCH_ASSOC)) !== false) {
                          $attachment_table .= '<tr>';
                          $attachment_table .= "<td><input name='checkbox[]' type='checkbox' id='checkbox[]' value='${row73[imageven_id]}'></td>";
                          $attachment_table .= "<td><a href='../php/viewimages.php?id=${row73[image_id]}')'>${row73[upload_name]}</a></td>";
                          $attachment_table .= "<td>${row73[image_category]}</td>";
                          $attachment_table .= "<td>${row73[upload_date]}</td>";
                          $attachment_table .= '</tr>';
                      };

?>    

<script type="text/javascript">

        function stopUpload(success) {
            var result = '';
            if (success == 1) {
                window.top.document.getElementById('attachment_table').innerHTML = <?php echo $attachment_table; ?>;
                document.getElementById('result').innerHTML = '<div class="msg-status" style="width:492px;">The file was uploaded successfully!<\/div><br/>';
            } else if (success == 0) {
                document.getElementById('result').innerHTML = '<div class="msg-error" style="width:492px;">There was an error during file upload!<\/div><br/>';
            } else if (success == 2) {
                document.getElementById('result').innerHTML = '<div class="msg-error" style="width:492px;">ERROR! Please upload a document with the following file types....<br/><br/>txt, doc, xls, rtf, ppt, pdf, jpg, jpeg, gif, png, xlsx, docx, png, pps, ppsx, ppt<\/div><br/>';
            }
            document.getElementById('f1_upload_process').style.visibility = 'hidden';
            return true;
        }
    </script>

modal_window_process.php - 处理数据库代码并发送 $result 响应

<script language="javascript" type="text/javascript"> 
window.top.window.stopUpload(<?php echo $result;?>);
</script>

有人可以指出我正确的方向吗?我在网上找不到任何关于如何做到这一点的信息,而且我是一个自学成才的菜鸟。谢谢。

4

1 回答 1

0

如果 iframe 父级有这个功能

<script type='text/javascript'>
    function onUploaderReady() {
        alert('upload ready');
    }
</script>

您可以让 modal_window_process.php 脚本通过返回这样的响应来调用onUploaderReady函数

<html>
<head>
    <script type='text/javascript'>
        parent.onUploaderReady();
    </script>
</head>
</html>
于 2012-11-10T19:48:22.927 回答