简体   繁体   English

使用javascript更新父div

[英]Update a parent div using javascript

So I have several modal windows on my site. 所以我的网站上有几个模态窗口。 I usually use jquery and ajax to accomplish something in the modal window and to update a div on the parent page. 我通常使用jquery和ajax在模式窗口中完成某些操作,并更新父页面上的div。

My problem here is I'm uploading files so I'm forced to use an iframe which I never do and Im using javascript, not jquery which I never do, so I'm a little lost and looking for some direction. 我的问题是我正在上传文件,因此我被迫使用我从未使用过的iframe,我被迫使用javascript,而不是我从未使用过的jquery,因此我有点迷失了方向。

I'm trying to update a div on the parent page from my modal window. 我正在尝试从模态窗口更新父页面上的div。 In the modal window I have a form which targets an iframe and the action is directed at a separate php page. 在模式窗口中,我有一个针对iframe的表单,该操作针对的是单独的php页面。 The overall question is how do I send an updated $attachment_table to a parent div after the form has uploaded its files? 总体问题是,在表单上传文件后,如何将更新后的$ attachment_table发送给父div? I'm trying: 我正在努力:

Modal_window.php - has a form on it that uploads files. 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 - Processes database code and sends response which is $result modal_window_process.php-处理数据库代码并发送$ result响应

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

Can someone point me in the right direction please? 有人可以指出我正确的方向吗? I couldn't find anything on the web on how to do this and I'm a self taught noob. 我在网上找不到有关如何执行此操作的任何信息,而且我是一个自学成才的菜鸟。 Thx. 谢谢。

If the iframe parent has this function 如果iframe父级具有此功能

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

You can have the modal_window_process.php script call the onUploaderReady function by returning a response like this 您可以通过返回类似这样的响应,使modal_window_process.php脚本调用onUploaderReady函数。

<html>
<head>
    <script type='text/javascript'>
        parent.onUploaderReady();
    </script>
</head>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM