javascript - 如何将 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 page
https://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?
你能帮我吗?
谢谢
解决方案
正如博主可能建议的那样,将 PHP 服务器设置为 REST 端点并使用异步 JavaScript 和 XML 访问博客站点上的数据。尽管今天人们倾向于从头开始研究 XML 部分并使用 JSON 或其他东西。AJAX 是通过使用XMLHttpRequest
对象来完成的。
Mozilla 的规范提供了链接和资料,它们将向您展示如何使用它
,而w3schools 是一个很好的资源。
然后一切都归结为直接编辑页面
element.removeChild(element.lastChild);
element.appendAdjacentHTML('beforeend',xhr.responseText);
推荐阅读
- javascript - 如何使用 javascript 获取 {{form}} 值?
- python - 如何获取看起来像目标文件的文件?
- html - 如何在html中并排对齐图像和标签?
- python - 使用 Python 脚本,评估 excel 公式(不使用宏)
- node.js - 如何将我的结果数组从 JS 文件到我的 ejs 页面..给出完整的代码细节
- python - Django没有名为'main'的模块
- javascript - 如何测量 Qml 应用程序启动时间?/开机持续时间?
- java - 重构如果抛出一些异常则返回 false 的方法
- java - 如何将存储在移动设备中的录制视频的 Uri 传递给另一个活动
- gitlab - GitLab 中的“无法在 struct ObjectMeta 中为 json 字段“数据”找到 api 字段”的错误是什么?