-------------jsp
<c:if test="${dataListLength > 0 }">
<div class="list_style_page">
<input type="hidden" id="page" name="page" value="${page }"/>
<input type="hidden" id="totalPage" name="totalPage" value="${totalPage }"/>
<input type="hidden" id="total" name="total" value="${total }"/>
<input type="hidden" id="pageSize" name="pageSize" value="${pageSize }"/>
<div id="pageDiv" class="pagination"></div>
</div>
</c:if>
-------------js
<script type="text/javascript">
var items_per_page = 2;
var page_index = 0;
function getDataList(index){
var pageIndex = index;
$.ajax({
type: "post",
dataType: "json",
url: "${path}/opinionAction!getOpinionShowByAjax.do",
data: "page="+pageIndex+"&pagesize="+items_per_page+"&opinion.opcollid="+$("#opinioncollectionid").val(),
success: function(data,textStatus){
var line = "";
$.each(data, function (index,value) {
var idx=index;
if(idx==0)
{
idx=1;
}
else{
idx=0;
}
var dc=2*pageIndex-idx;
line+="<div class='opinion-list translateBG' defaultColor='#fff' translateColor='#f8f8f8' style='cursor: default;'>";
line+="<p class='opinion-desc'>第"+dc+"位网友:姓名:"+value.creator+" 于"+value.createdates+" 发表以下意见:</p>";
line+="<div class='opinion-content'>"+value.content+"</div>";
line+="</div>";
});
$("#opinion").html(line);
},error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("error:"+errorThrown);
}
});
}
function pageselectCallback(page_index, jq){
page_index=page_index+1;
getDataList(page_index);
}
/* $(document).ready(function(){
getDataList(page_index);
}); */
//分页-只初始化一次
if($("#pageDiv").html().length == ''){
$("#pageDiv").pagination($("#total").val(), {
items_per_page : items_per_page,
num_display_entries : 10,
current_page:$("#totalPage").val()-1,
num_edge_entries : 2,
prev_text : "上一页",
next_text : "下一页",
link_to : "javascript:void(0);",
callback : pageselectCallback
});
}
</script>
----------------action
public void getOpinionShowByAjax(){
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
currentUser = super.getLoginUsers();
try {
opinion.setStatus(Opinion.STATUS.IS_SHOW); //显示在信用网站的数据
this.setPageSize(2);
total = opinionManager.getOpinionCount(opinion);
super.doPage(total,this.getPageSize());
dataList = opinionManager.getOpinionList(opinion,startRownum,endRownum,"CREATEDATE", "ASC");
for (int i =0; i<dataList.size();i++) {
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
dataList.get(i).setCreatedates(format.format(dataList.get(i).getCreatedate()));
}
JSONArray jsonArray = JSONArray.fromObject(dataList);
response.getWriter().write(jsonArray.toString());// 返回json类型对象
response.getWriter().close();
} catch (OpinionException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}