Disqus API评论计数教程 - 我在哪里放javascript代码?

时间:2013-10-01 08:57:12

标签: javascript api disqus

我正在尝试解决我在这里做错了什么,因为它没有用。

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

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

谢谢, SAR

这是我的代码:

    <!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”>
                <h2>Test Post One</h2>
                <div class=”count-comments” data-disqus-url=”http://www.mysite.com/folder/page-1.html”></div>
            </a>
        </div>
  <div>
            <a href=”folder/page-2”>
                <h2>Test Post Two</h2>
                <div class=”count-comments” data-disqus-url=”http://www.mysite.com/folder/page-2.html”></div>
            </a>
        </div>


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

0 个答案:

没有答案