如何将json计入html span [英] How to count json into html span

查看:37
本文介绍了如何将json计入html span的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试通过HTML Span将不和谐的会员数计入我的网站.

i try to count my members on discord into my website with a HTML Span.

我无法正常工作

源代码: https://discordapp.com/api/guilds/366996506563051520/embed.json

推荐答案

在这里为您配上了准系统脚本.只需将其插入页面的< body>

Got a barebones script for you here mate. Just insert it in the <body> of your page

<span id="discord-counter"></span>
    <script type="text/javascript">
        var request = new XMLHttpRequest();

        request.open('GET', 'https://discordapp.com/api/guilds/366996506563051520/embed.json', true);

        request.onload = function() {
          if (request.status >= 200 && request.status < 400) {
            // Success!
            var data = JSON.parse(request.responseText);
            document.getElementById("discord-counter").innerHTML = data.members.length;

          } else {
            // We reached our target server, but it returned an error

          }
        };

        request.onerror = function() {
          // There was a connection error of some sort
        };

        request.send();
    </script>

这篇关于如何将json计入html span的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆