前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >通过post请求api获取土味情话

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

作者头像
岳泽以
发布2022-10-26 17:29:43
6970
发布2022-10-26 17:29:43
举报
文章被收录于专栏:岳泽以博客岳泽以博客

用的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>
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022 年 09 月,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档