Skip to content

Instantly share code, notes, and snippets.

@learningjs
Created December 29, 2013 21:05
Show Gist options
  • Save learningjs/8174821 to your computer and use it in GitHub Desktop.
Save learningjs/8174821 to your computer and use it in GitHub Desktop.
Code used to retrieve an user's watched repositories on Github. Always returns 30 results.
fetchJSONFile("https://api.github.com/users/" + userName + "/subscriptions", function(data){
...
}
function fetchJSONFile(path, callback) {
var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function() {
if (httpRequest.readyState === 4) {
if (httpRequest.status === 200) {
var data = JSON.parse(httpRequest.responseText);
if (callback) callback(data);
}
}
};
httpRequest.open('GET', path);
httpRequest.send();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment