带分页的Json
function TrackPage(PageNum) { var PageSize = 10; //分页数 var StartIndex = (PageNum - 1) * PageSize + 1; var EndIndex = (PageNum - 1) * PageSize + PageSize; var ItemCount = 0; //总记录数 var url = '/DataAjax.aspx?f=UserId=<%=Request.QueryString["Id"]%>&StartIndex=' + StartIndex + '&EndIndex=' + EndIndex; $.getJSON(url, function (data) { var str = '<table class="grid"><caption>JSON分页</caption>'; str += '<th style="width: 20%">ID</th>'; str += '<th style="width: 40%">姓名</th>'; $.each(data, function (i, list) { str += '<tr>'; str += '<td>' + list.Id + '</td>'; str += '<td>' + list.Name + '</td>'; str += '</tr>'; ItemCount = list.RecordCount; }); var allPage = ItemCount % PageSize > 0 ? (parseInt(ItemCount / PageSize) + 1) : parseInt(ItemCount / PageSize); //计算总页数 str += '<tr><td colspan="5" style="text-align:center;">'; if (ItemCount > 0) { str += '总记录数:' + ItemCount + ' 当前页:' + PageNum + '/' + allPage + ' '; if (PageNum > 1 && PageNum <= allPage) { str += ' <a οnclick="TrackPage(' + (1) + ');">首页</a>'; str += ' <a οnclick="TrackPage(' + (PageNum - 1) + ');">上一页</a>'; } else { str += ' 首页 上一页'; } if (allPage > 1 && PageNum < allPage) { str += ' <a οnclick="TrackPage(' + (PageNum + 1) + ');">下一页</a>'; str += ' <a οnclick="TrackPage(' + (allPage) + ');">尾页</a>'; } else { str += ' 下一页 尾页'; } } str += '</td></tr>'; str += '</table>'; $("#UserListDiv").html(str); }); }