douzhu3367 2012-11-10 19:34
浏览 22

使用javascript更新父div

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.

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.

I'm trying to update a div on the parent page from my modal window. In the modal window I have a form which targets an iframe and the action is directed at a separate php page. The overall question is how do I send an updated $attachment_table to a parent div after the form has uploaded its files? I'm trying:

Modal_window.php - has a form on it that uploads files.

<?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

<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.

  • 写回答

1条回答 默认 最新

  • dongzhong8691 2012-11-10 19:48
    关注

    If the iframe parent has this function

    <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

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

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?