Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save chrisjason/3139054 to your computer and use it in GitHub Desktop.
Save chrisjason/3139054 to your computer and use it in GitHub Desktop.
Sample code for looping through ESPN Headlines API response and printing story headlines, using JQuery.
// Example JSONP request with jQuery
$.ajax({
url: "http://api.espn.com/v1/sports/news/headlines",
data: {
// enter your developer api key here
apikey: "{api key}",
// the type of data you're expecting back from the api
_accept: "application/json"
},
dataType: "jsonp",
success: function(data) {
// create an unordered list of headlines
var ul = $('<ul/>');
$.each(data.headlines, function() {
var li = $('<li/>').text(this.headline);
ul.append(li)
});
// append this list to the document body
$('body').append(ul);
},
error: function() {
// handle the error
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment