首页 > 解决方案 > 如何将 PHP 页面添加到 blogspot.com 新页面

问题描述

我有一个像这样的真实 .php 页面http://hiteachers.com/soccer_parse.php?id=5。我想将它添加到一个blogger.com新页面中(**不是新的博客文章或新的 HTML 小部件**,我已经成功地做到了。

https://tranbongda.blogspot.com/p/function-myfunction-window.html

我使用这样的代码:

<script> 
  var Window; 
  // Function that open the new Window 
  function windowOpen() { 
      Window = window.open("http://hiteachers.com/soccer_parse.php?id=5", 
                             "_blank", "width=400, height=450"); 
  } 
  // function that Closes the open Window 
      function windowClose() { 
            Window.close(); 
   } 
 </script> 
<button onclick="windowOpen()">Open page</button> 
    <button onclick="windowClose()">Close page</button> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script>
  $(document).ready(function()
  $("button").click(function(){
    $("#div1").load("http://hiteachers.com/soccer_parse.php?id=5");
  });
});
</script>

我的期望是,当访问者访问 blogger.com 页面 ( ) 时,我希望在不点击任何按钮的情况下立即blogger page加载原始内容。.php pagehttps://tranbongda.blogspot.com/p/function-myfunction-window.html

我曾想过使用以下方法创建 iframe:

<iframe name="Framename" src="http://hiteachers.com/soccer_parse.php?id=5" width="550" height="550" frameborder="0" scrolling="yes" style="width: 100%;"> </iframe>

但是 blogger.com 页面不接受它,并返回如下错误消息: This page contains HTTP resources which may cause mixed content affecting security and user experience if blog is viewed over HTTPS.

然后我根据一些博主的建议开始尝试这个<object width="500" height="300" type="text/html" data="http://hiteachers.com/soccer_parse.php?id=5"></object>,但我仍然失败了。

其他一些博主建议使用 AJAX,这对我来说很新。

那么,有什么方法可以解析provided .php page content并将其添加到blogspot.com/blogger.com new page不显示 .php 页面或窗口弹出窗口的 url?

你能帮我吗?

谢谢

标签: javascriptphpblogger

解决方案


正如博主可能建议的那样,将 PHP 服务器设置为 REST 端点并使用异步 JavaScript 和 XML 访问博客站点上的数据。尽管今天人们倾向于从头开始研究 XML 部分并使用 JSON 或其他东西。AJAX 是通过使用XMLHttpRequest对象来完成的。 Mozilla 的规范提供了链接和资料,它们将向您展示如何使用它 ,而w3schools 是一个很好的资源。

然后一切都归结为直接编辑页面

element.removeChild(element.lastChild);
element.appendAdjacentHTML('beforeend',xhr.responseText);

推荐阅读