【发布时间】:2020-04-14 13:13:39
【问题描述】:
我只想复制shizyab.ir/rand.php 中的所有texes 并通过javascript 将其粘贴到我的html 文件中。我该怎么办?
【问题讨论】:
标签: javascript html dom copy copy-paste
我只想复制shizyab.ir/rand.php 中的所有texes 并通过javascript 将其粘贴到我的html 文件中。我该怎么办?
【问题讨论】:
标签: javascript html dom copy copy-paste
这是一个不需要jquery的版本:
function insertPage() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
var element = document.createElement("div");
element.innerHTML = this.responseText;
document.body.appendChild(element);
};
xhttp.open("GET", "https://www.shizyab.ir/rand.php", true);
xhttp.send();
}
并运行此代码:insertPage();
【讨论】:
您可以通过在window.onload 上的脚本中使用带有 jquery 的 ajax 调用来做到这一点:
假设你的 php 脚本返回一个 json 对象。
function getData(username, callback) {
var url = 'shizyab.ir/rand.php';
$.ajax({
url:(url),
type: 'GET',
dataType: 'json',
success: (data) => {
callback(data);
}
});
}
然后在callback函数中处理你的数据显示。
【讨论】: