首页 > 代码库 > ajax分页

ajax分页

<!--分页-->
<script type="text/javascript">
//第几页
var page = 1;
//每页显示的条数
var num = 5;
//加载数据
Load();
//加载分页
LoadFenYe();
//加载数据的方法
function Load()
{
	var send = $("#cc1").val();
	$.ajax(
		{
			url:"fenye_chuli.php",
			data:{page:page,num:num,send:send},
			type:"POST",
			dataType:"JSON",
			success: function(data)
				{
					var str = "";
					for(var k in data)
					{
						str = str+"<tr><td>"+data[k].squid+"</td><td>"+data[k].ftime+"</td><td>"+data[k].didian+"</td><td>"+data[k].comment+"</td></tr>";
					}
					$("#shuju").html(str);
				}
		});
}
//加载分页的方法
function LoadFenYe()
{
	var s = "";
	var send = $("#cc1").val();
	s = "<span id=‘prev‘>上一页</span>";
	var zts = 0;
	$.ajax(
		{
			async:false,
			url:"fenye_zongtiaoshu.php",
			data:{send:send},
			type:"POST",
			dataType:"TEXT",
			success: function(data)
				{
					zts = data;
				}
		});
		var zys = Math.ceil(zts/num);
		page = parseInt(page);
		for(var i = page-2;i < page+3;i++)
		{
			if(i>0 && i<=zys)
			{
				if(i==page)
				{
					s = s+"<span ys=‘"+i+"‘ class=‘dqy‘>"+i+"</span>";
				}
				else
				{
					s = s+"<span ys=‘"+i+"‘ class=‘qty‘>"+i+"</span>";
				}
			}
		}
	s = s +"<span id=‘next‘>下一页</span>";
	s = "<li>"+s+"</li>";
	$(".xinxi").html(s);
	$("#prev").click(function()
			{
				page = parseInt(page);
				if(page>1)
				{
					page--;
				}
				Load();
				LoadFenYe();
			})
	$(".qty").click(function()
			{
				page = parseInt($(this).attr("ys"));
				Load();
				LoadFenYe();
			})
	$("#next").click(function()
			{
				page = parseInt(page);
				if(page<zys)
				{
					page++;
				}
				Load();
				LoadFenYe();
			})
}
$("#cc2").click(function()
	{
		Load();
		LoadFenYe();
	})

  

ajax分页