Skip to content

Instantly share code, notes, and snippets.

@netshade
Created November 17, 2011 23:18
Show Gist options
  • Save netshade/1374899 to your computer and use it in GitHub Desktop.
Save netshade/1374899 to your computer and use it in GitHub Desktop.
JSONP Twitter Search
<html>
<head>
<script type="text/javascript">
function showStories(the_object){
var titles = [];
for(var i = 0; i < the_object.results.length; i++){ // the object coming back from twitter is an object that contains the results in a member named results
titles.push("<li>" + the_object.results[i].text + ": " + the_object.results[i].from_user_name + "</li>");
}
document.getElementById("story_list").innerHTML = titles.join("\n");
}
</script>
</head>
<body>
<ul id="story_list">
</ul>
<script type="text/javascript"
src="http://search.twitter.com/search.json?q=skyrimstories&callback=showStories"></script>
</body>
</html>
@netshade
Copy link
Author

Note that I defined the function in the document /head/ to ensure that the method is available for the entire page, while I kept the Twitter script load at the foot of the body. I did that just to ensure that our function doesn't get called until the rest of the page has rendered and is available to access ( namely, the ul#story_list element ).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment