dongyikong6207 2015-11-09 11:59
浏览 42
已采纳

发掘一个js php加载/执行问题

Running a base web framework from https://github.com/panique/huge/

The overarching problem I have is: html table needing live updates to account for database (mysql) changes.

Where I'm stuck: I have added to the index/index.php page, the following javascript code to the end of the file (note: header and footers loaded around this index/index.php page) in attempt to refresh the need for updating the table every few seconds in order reload the html table based off of the mysql database state. The index/tableChange module simply gathers the mysql data and returns the query.

<?php echo "
  <script language='javascript' type='text/javascript'>
    function loadlnk() {
      document.getElementById('tableHolder').innerHTML =
        \"<object type=\"text/html\" data=\"<?php echo config::get('URL'); ?>index/tableChange\"></object>\";
      setTimeout(loadlnk, 3000);
    }
    loadlnk();
  </script>";
?>

When I test the index/tableChange snippet out, I am able to load the php by itself in its own individual webpage (but for the purpose of this question, I'm needing to load that content of tableChange into the index/index page).

I also tried adding the $(document).ready(function() { around inside of the script, but this didn't seem to help accomplish anything visible to changing the table.

I looked at what I understood and could find, but I don't think it's a quote issue.

  • 写回答

1条回答 默认 最新

  • dra8603 2015-11-09 12:25
    关注

    You might like to remove the inner PHP tags and the echo statement and try like this:

    <?php
    
      echo "
      <script language='javascript' type='text/javascript'>
        function loadlnk() {
          document.getElementById('tableHolder').innerHTML =
            \"<object type=\"text/html\" data=\"" . config::get('URL') ."index/tableChange\"></object>\";
          setTimeout(loadlnk, 3000);
        }
        loadlnk();
      </script>";
    
    ?>
    

    I found that I was getting an error in the console, similar to the following:

    Load denied by X-Frame-Options: https://localhost/test/target.php does not permit framing.

    The solution, at least a quick one in this instance was to add a header before sending the output from /test/target.php ~ name header('X-Frame-Options: sameorigin'); then it worked just fine.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 Keil编译时报错"no source": Error: #5: cannot open source
  • ¥50 操作系统时间无法更新
  • ¥20 Windows11, usb转hdmi,外接显示器无反应
  • ¥20 怎么在JavaFx的TableView中动态地添加数据。
  • ¥15 MFC里的工具栏按钮图标使用外部图片
  • ¥15 如何在 llama.cpp 服务器中实现用户登录功能的优化方案?(语言-c++)
  • ¥15 有会用octave 的吗,急!代做!好偿!
  • ¥15 有一套同城小程序源码,Uniapp前端,php+html+mysql后端 ,能不能教我搭建起来可以运行,我不知道怎样操作
  • ¥15 mac调用java.io接口无法在根目录生成文件
  • ¥15 java微服务节点假死,网关路由时长延迟