<div class="rank"> <div class="title">排行榜</div> <table id="fresh"> <tr> <th>节目名称</th> <th>表演部门</th> <th>获得票数</th> </tr> <{foreach from=$rank item=r}> <tr add='true'> <td><{$r.program_name}></td> <td><{$r.department}></td> <td><{$r.votes}></td> </tr> <{/foreach}> </table> </div>
<script type="text/javascript"> $(function(){ var timer=null; timer=setInterval(function(){ var content=''; $.ajax({ type: 'POST', url: '?program-rankAjax.html', dataType: 'json', success:function(json){ // 二维数组处理 /*$('#fresh').find('tr[add]').remove(); for (var i = 0; i < json.length; i++) {//each content+='<tr add="true"><td>'+json[i].program_name+'</td><td>'+json[i].department+'</td><td>'+json[i].votes+'</td></tr>'; } $("#fresh").append(content);*/ $('#fresh').find('tr[add]').remove(); $.each(json,function(k,v){ content+='<tr add="true"><td>'+v.program_name+'</td><td>'+v.department+'</td><td>'+v.votes+'</td></tr>'; }); $("#fresh").append(content); } }); },6000); }) </script>