Created
November 21, 2012 16:45
-
-
Save chrisjason/4125956 to your computer and use it in GitHub Desktop.
Sample code for looping through ESPN Research Notes API, 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/notes", | |
| 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 research notes | |
| var ul = $('<ul/>'); | |
| $.each(data.notes, 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