JSFiddle - React, Tailwind, and code Playground
HTML
<p>fiddle for <a href="http://stackoverflow.com/questions/5299674/accessing-json-service-from-localhost-or-file/">http://stackoverflow.com/questions/5299674/accessing-json-service-from-localhost-or-file/</a></p><br />
<h2>Tweets from 'someuser' should appear here on load</h2>
<div style="border: 1px solid #666" id="placeholder">
</div>
<h2>Tweets for the query 'stackoverflow' should appear here on load</h2>
<div style="border: 1px solid #666" id="placeholder2">
</div>
JavaScript
//get statuses for 'someuser'
$.getJSON("http://api.twitter.com/1/statuses/user_timeline.json?screen_name=wpval&count=9&callback=?", {},
function (data) {
if(data){
$.each(data, function(index, el){
$('#placeholder').append('<span>' + el.text + '</span><br />');
});
}
});
//get search results for 'stackoverflow'
$.getJSON("http://search.twitter.com/search.json?q=stackoverflow&result_type=recent&count=9&callback=?", {},
function (data) {
if(data && data.results){ //check that we have a data object and that it has a results array
$.each(data.results, function(index, el){
$('#placeholder2').append('<span>' + el.text + '</span><br />');
});
}
});