通过post请求api获取土味情话

2022-10-26 17:29:43 浏览数 (1)

用的ALAPI,自己申请token填上即可。

代码语言:javascript复制
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.zeyiwl.cn/jQuery/jquery-1.9.1.min.js"></script>
    <style>
        .btn {
            text-align: center;
        }

        #btnGET {
            background-color: #4CAF50;
            /* 绿色 */
            border: none;
            color: white;
            padding: 20px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 16px;
            margin: 4px 2px;
            cursor: pointer;
            border-radius: 10px;
        }

        .dd {
            padding: 10px;
            width: 500px;
            margin: 100px auto;
            text-align: center;
            color: #000;
            border: 2px solid pink;
        }
    </style>
</head>

<body>


    <div class="dd">点击下方按钮开始获取土味情话吧~</div>
    <div class="btn">
        <button id="btnGET">
            获取情话
        </button>
    </div>
    <script>
        var dd = document.querySelector('.dd')
        $(function () {
            $('#btnGET').on('click', function () {
                $.post('https://v2.alapi.cn/api/qinghua', {
                    format: "json",
                    token: "填自己的token"
                },
                    function (res) {
                        if (res.code !== 200) return alert('数据加载失败')
                        var arr = res.data
                        $.each(arr, function (content, value) {
                            dd.innerText = value;
                        })
                    }
                )

            })
        })


    </script>
</body>

</html>

0 人点赞