Dribbble api返回不匹配的数据,例如镜头评论

时间:2015-08-20 22:52:07

标签: ajax

我最近一直在使用Dribbble api,并且遇到了一个奇怪的错误,即所谓的comments_count与返回的评论数量不匹配。

我为你们创建了一个可以证明这个问题的编解码器。

这是api的问题还是我错过了什么?

http://codepen.io/matt3224/pen/bdxwoV?editors=011

这是来自上述示例的代码:

$.ajax({

    url: 'https://api.dribbble.com/v1/shots/?per_page=20',
    beforeSend: function(xhr) {

        xhr.setRequestHeader('Authorization', 'Bearer 75913cbbec4e93dae61f6d4bfa9ba3ae35fe62b4cf2c3aa074f171e4e7f62996');

    },
    success: function(data){

        $(data).each(function(){

            var comments_count = this.comments_count;

            $.ajax({

                url: this.comments_url,
                beforeSend: function(xhr) {

                    xhr.setRequestHeader('Authorization', 'Bearer 75913cbbec4e93dae61f6d4bfa9ba3ae35fe62b4cf2c3aa074f171e4e7f62996');

                },
                success: function(data){

                    var mismatch = comments_count !== data.length ? true : false;
                    if(mismatch){
                        $('.out').append('<p class="mismatch">There should be ' + comments_count + ' comments, but there are actually ' + data.length + '</p>');
                    } else {
                        $('.out').append('<p>There should be ' + comments_count + ' comments, but there are actually ' + data.length + '</p>');
                    }

                }

            });

        });

    }

});

谢谢

0 个答案:

没有答案