为了账号安全,请及时绑定邮箱和手机立即绑定

如何通过JS访问另一个页面

如何通过JS访问另一个页面

拉风的咖菲猫 2023-12-19 21:31:33
我只想复制 shizyab.ir/rand.php 中的所有文本并通过 javascript 将其粘贴到我的 html 文件中。我该怎么办?
查看完整描述

2 回答

?
holdtom

TA贡献1805条经验 获得超10个赞

这是一个不需要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();


查看完整回答
反对 回复 2023-12-19
?
噜噜哒

TA贡献1784条经验 获得超7个赞

您可以通过在 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函数中处理数据显示。


查看完整回答
反对 回复 2023-12-19
  • 2 回答
  • 0 关注
  • 75 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信