2

I would like to access my public gists through javascript, but the following code doesn't work:

$(document).ready(function() {

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

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

What's wrong?

2 Answers 2

2

This is probably a same-origin policy problem. The GitHub API supports JSONP, so you can use that. jQuery picks up on callback=? in your URL and will automatically use 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"
});
Sign up to request clarification or add additional context in comments.

1 Comment

John, would a request to gist.github.com/raw/3849235/… also require a callback?
0

You can not request resource from different origin with JavaScript because of the Access-Control-Allow-Origin, for more about gist api, please checkout this:http://developer.github.com/v3/gists/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.