Skip to content

Instantly share code, notes, and snippets.

@tomekr
Created July 12, 2012 02:17
Show Gist options
  • Save tomekr/3095243 to your computer and use it in GitHub Desktop.
Save tomekr/3095243 to your computer and use it in GitHub Desktop.
function getFrontPage() {
var req = new XMLHttpRequest();
console.log("about to attempt a get!");
req.open("GET", "http://www.reddit.com/r/listentothis.json", true);
req.onreadystatechange = function() {
console.log(req.status);
if (req.readyState == 4) {
if (req.status == 200) {
console.log("Fetch complete! Parsing!");
// Parse the JSON response
response = JSON.parse(req.responseText);
children = response.data.children;
console.log(children);
titles = children.map(function(o){ o.data });
console.log(titles);
}
}
};
req.send();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment