无法从Stack Exchange API JSON调用获取发布数据

时间:2013-06-17 14:17:06

标签: jquery json

我正在尝试使用JSON和jQuery从Stack Exhange帖子ID中动态填充我的应用中的 post 区域,但我似乎无法获取数据以填充元件。

/* Get post info */
function getPost(id) {
    $.ajax({
        url: 'http://api.stackexchange.com/2.1/questions/' + id,
        dataType: 'jsonp',
        jsonp: 'jsonp',
        data: {
            filter: 'cvwvFLMyvV',
            site: 'stackoverflow',
        },
        success: function (data) {
            $('article.post-view div.post-info h2').text(data.title);
            $('article.post-view div.post-entry').html(data.body);
        }
    });
}

/* Click to toggle */
$('body').on('click', 'a', function (event) {
    var postID = $(this).data('id');
    getPost(postID);
});

HTML:

<article class=post-view>
    <div class=post-content>
        <div class=post-info>
            <h2></h2>
        </div>
        <div class=post-entry></div>
    </div>
</article>

<a href="#" data-id="628500" class=postfill>Click Me!</a>

以下是我正在做的事:http://jsfiddle.net/c4WRk/2/

getPost()似乎不起作用。有人知道我是怎么做到的吗?

0 个答案:

没有答案