jquery+ajax实现排名小应用

来源:互联网 发布:pdfobject.js免费下载 编辑:程序博客网 时间:2024/04/30 02:46

在action中读取数据库数据并做好排序,

在struts.xml中

<package name="example" extends="json-default">
  <action name="test"
   class="com.test">
   <result type="json"></result>
  </action>
 </package>

使用json插件jar包jsonplugin-0.33.jar

js文件:

 <script>   
   $(function(){
    $.getJSON(‘action的url地址’,function(data){
    $.each(data,function(entryIndex,entry){          
     for(var i=0;i<$(entry).size();i++){
     var html="<tr height='26'>";
  html+="<td width='52' align='center' valign='middle'>"+(i+1)+'</td>';
  html+="<td width='100' align='center' valign='middle'>"+(entry[i].userName.substring(0,2)+"***")+"</td>";
  html+="<td width='125' align='center' valign='middle'>"+entry[i].voteAccount+'</td>';
  html+='</tr>';
  $(html).appendTo($('#ccbXc'));
  }
     });
    });
   });

  </script>