这是工作示例:
<html><head><title>Twitter 2.0</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
</head><body>
<div id='tweet-list'></div>
<script type="text/javascript">
$(document).ready(function() {
var url = "http://api.twitter.com/1/statuses/user_timeline/codinghorror.json";
$.getJSON(url + "?callback=?", null, function(tweets) {
for(i in tweets) {
tweet = tweets[i];
$("#tweet-list").append(tweet.text + "<hr />");
}
});
});
</script>
</body></html>
注意所?callback=?
请求URL的末尾。这表明getJSON
我们要使用JSONP。删除它,将使用原始的JSON请求。由于相同的原产地政策而失败。
您可以在JQuery网站上找到更多信息和示例:http ://api.jquery.com/jQuery.getJSON/