Created
July 18, 2012 21:31
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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