dpzp5127 2016-06-15 19:49
浏览 205

Ajax结果加载到iframe中

I have a Ajax post that returns the path to a PDF file i can not seem to get it to open the pdf in an Iframe of on the parent page.

Parent Page:

     <div  id = "mainpage" ></div>
     <iframe class ="box2" id="myFrame2"  width="600px" height="700px"   scrolling="yes" align="right">
     </iframe>
</div>
<script>
  function onAjaxComplete(msg)
    {
      $("#mainpage").html(msg);
      // alert(msg);
      }

when I click on the ajax request it returns the correct value and the function will display the results in the div but I can not get it to open the pdf file in the iframe.

This is the PHP script for the call from Ajax:

 <?php
  $sitej = $_POST['site'];
  $filenamej = $_POST['filename'];
  $pagej = $_POST['page'];
  $path = "scann/" . $sitej . "/" . $filenamej;

  //var_dump($_POST);
 $load = "$path/#page=$pagej ";
 //$open =      '<a href="' . $path . '/#page=' . $pagej . '">';
  //$load = '<a  target="myFrame2" href="'. $open . '">';
 echo $load;

 ?> 

Any suggestions? Thank you in advance!

  • 写回答

1条回答 默认 最新

  • douchun5976 2016-06-15 20:16
    关注

    Change your jQuery to add the msg to the iframe src attribute:

    function onAjaxComplete(msg){
          $("#myFrame2").attr('src', msg); //No reason to select the div if you want to change the iframe src
          // alert(msg);
    }
    

    This will return the iframe with the src from the php file.

    评论

报告相同问题?

悬赏问题

  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害