3

我正在尝试解决我在这里做错的事情,因为它不起作用。

我一直在关注 Disqus API 教程:http: //help.disqus.com/customer/portal/articles/1131783-tutorial-get-comment-counts-with-the-api

我已经关注了所有内容,但是当我单击按钮时没有任何反应。这里有很多变量可能出错,但我希望这只是我的 HTML。

谢谢,萨尔

这是我的代码:

    <!DOCTYPE html>
    <html>
        <head>
            <title>Disqus Comment Counts Example</title>

    <script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>


    <script type="text/javascript">
    $(document).ready(function () {
      var disqusPublicKey = "DELETED FOR SECURITY -DISQUSPUBLICKEY";
      var disqusShortname = "DELETED FOR SECURITY-MYDISQUSSHORTNAME"; // Replace with your own shortname

      var urlArray = [];

    $('.count-comments').each(function () {
      var url = $(this).attr('data-disqus-url');
      urlArray.push('link:' + url);

    });


    $('#get-counts-button').click(function () {
      $.ajax({
        type: 'GET',
        url: "https://disqus.com/api/3.0/threads/set.jsonp",
        data: { api_key: disqusPublicKey, forum : disqusShortname, thread : urlArray },
        cache: false,
        dataType: 'jsonp',
        success: function (result) {

          for (var i in result.response) {

            var countText = " comments";
            var count = result.response[i].posts;

            if (count == 1)
              countText = " comment";

            $('div[data-disqus-url="' + result.response[i].link + '"]').html('<h4>' + count + countText + '</h4>');

          }
        }
      });
    });

    </script>

     </head>
        <body>
            <h1>Comment Counts Example</h1>



 <div>
            <a href=” folder/page-1.html”&gt;
                <h2>Test Post One</h2>
                <div class=”count-comments” data-disqus-url=”http://www.mysite.com/folder/page-1.html”&gt;</div>
            </a>
        </div>
  <div>
            <a href=”folder/page-2”&gt;
                <h2>Test Post Two</h2>
                <div class=”count-comments” data-disqus-url=”http://www.mysite.com/folder/page-2.html”&gt;</div>
            </a>
        </div>


            <button type="button" id="get-counts-button">Get Comment Counts</button>
     </body>
    </html>
4

0 回答 0