Ajax在线抓取json数据并渲染到自己的界面

本文介绍如何利用Ajax从在线网站抓取JSON数据,并通过PHP读取后显示在自己的网页上。通过F12 Network面板找到XHR请求,转换JSON格式,然后在PHP和HTML中处理数据。
摘要由CSDN通过智能技术生成
  1. 获取在线网站数据
    基本所有网站都使用Ajax,在F12的Network选项中,选择XHR,找到json数据后,百度一个在线转化json格式,后复制进自己的json文档中即可
  2. php读取json后返回index页面
    index文档:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>index</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <script src="js/jqueryMin.js"></script>
    <script src="js/bootstrap.min.js"></script>
</head>
<style>
    p{
   
        font-size: 20px;
    }
    table{
   
        width: 1000px;
        height: 300px;
        border: 1px pink solid;
        margin-left: 300px;
        background-color: pink;
    }
    table td{
   
        margin: 2px;
        border:1px solid skyblue ;
        border-radius: 5px;
        text-align: center;
        line-height:;
    }
</style>
<body>
<button>获取json数据</button>
<div class="display"></div>
<script>
    $('button').on('click',function () {
   
        var jjson=new XMLHttpRequest();
        jjson.open('post','hello.php');
        jjson.setRequestHeader('Content-type','application/x-www-form-urlencoded');
        jjson.onreadystatechange=function (
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值