如何通过JS访问另一个页面
How to acsess another page by JS
我只想复制 shizyab.ir/rand.php 中的所有税款并通过 javascript 将其粘贴到我的 html 文件中。我该怎么办?
您可以通过在 window.onload
上的脚本中对 jquery 使用 ajax 调用来做到这一点:
假设您的 php 脚本 returns 一个 json 对象。
function getData(username, callback) {
var url = 'shizyab.ir/rand.php';
$.ajax({
url:(url),
type: 'GET',
dataType: 'json',
success: (data) => {
callback(data);
}
});
}
然后在callback
函数中处理你的数据显示。
这个版本不需要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();
我只想复制 shizyab.ir/rand.php 中的所有税款并通过 javascript 将其粘贴到我的 html 文件中。我该怎么办?
您可以通过在 window.onload
上的脚本中对 jquery 使用 ajax 调用来做到这一点:
假设您的 php 脚本 returns 一个 json 对象。
function getData(username, callback) {
var url = 'shizyab.ir/rand.php';
$.ajax({
url:(url),
type: 'GET',
dataType: 'json',
success: (data) => {
callback(data);
}
});
}
然后在callback
函数中处理你的数据显示。
这个版本不需要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();