2

JavaScript を使用してパブリック Gist にアクセスしたいのですが、次のコードは機能しません。

$(document).ready(function() {

    var url = 'https://api.github.com/users/binroot/gists';

    $.getJSON(url, function(data) {
        document.write(data[0].description);                                           
    });
});

どうしたの?

4

2 に答える 2

2

これはおそらく、同一生成元ポリシーの問題です。GitHub APIは JSONP をサポートしているので、それを使用できます。jQuery はcallback=?URL を検出し、JSONP を自動的に使用します。

$.getJSON('https://api.github.com/users/binroot/gists?callback=?', function(data) {
    // do whatever as before, but note that your data
    // will now be in a property called "data" with the
    // header information in "meta"
});
于 2012-10-09T02:26:29.463 に答える
0

Access-Control-Allow-Origin のため、JavaScript を使用して別のオリジンからリソースをリクエストすることはできません。Gist API の詳細については、http://developer.github.com/v3/gists/ を確認してください

于 2012-10-09T02:36:44.280 に答える