且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将json计入html span

更新时间:2023-02-19 16:11:57

在这里为您配上了准系统脚本.只需将其插入页面的< 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>