doushou9028 2018-04-01 20:20
浏览 154
已采纳

如何将其他页面中的HTML内容放入字符串?

I know that I can use document.documentElement.outerHTML to put the current page into a string, but I need to get other pages on the same website into a string from a certain, different page. The pages are php files, and my function is running from the parent index.php.

The ultimate goal for this is a site-wide search function.

  • 写回答

1条回答 默认 最新

  • dshdsh2016 2018-04-01 20:36
    关注

    JQuery has a really useful function called $.get(). Say I wanted to get the page example.com and put it into a string, I would use:

    $.get('http://www.example.com', function(data){
    
      //The local variable 'data' now has example.com stored inside of it here.
    
    });
    

    If you wanted to do this server-side using PHP, you can use file_get_contents, like so:

    <?php
        $otherPagesHTML = file_get_contents('http://www.example.com');
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图