【发布时间】:2012-01-31 19:45:05
【问题描述】:
我正在编写一个脚本,该脚本将从 Twitter API 中“获取”最新的推文,然后使用 JQuery 在我的页面上将它们显示为 HTML。
我是 JQuery 的新手,所以如果有人能指出 JQuery 网站上必要功能的方向,我将不胜感激。
我目前已经构建了以下脚本:
<!-- Use the Google jQuery CDN for lib support -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<!-- Setup and fetch the JSON data -->
<script type="text/javascript">
$(document).ready(function(){
var url='http://search.twitter.com/search.json?callback=?&q=@req';
$.getJSON(url,function(json){
<!-- Iterate the file -->
$.each(json.results,function(i,tweet){
$("#results").append('<p><img src="'+tweet.profile_image_url+'" widt="48" height="48" />'+tweet.text+'</p>');
$("#results").slideDown("slow");
});
});
});
</script>
<!-- Output the file into the DIV -->
<div id="results"></div>
脚本运行良好,但我现在想加入某种形式的内容自动刷新。即每 x 分钟“重新获取”一次提要。
据我了解,我需要将 .append 替换为 .html 以便在重新加载之前从页面中删除内容,但是是否有人对实际刷新内容的最佳方式有任何建议?我发现可能有文章表达了对浏览器内存泄漏等问题的担忧,并且不想走错路。
期待您的回复,再次感谢。
【问题讨论】:
标签: jquery json twitter refresh