您好,欢迎访问一九零五行业门户网

JQuery与JSon实现的无刷新分页代码_jquery

如图  
而无刷新分页可以解决这个问题,上面播放着视频,下面我点下一页看着评论,现在大部分的网站都是无刷新分页。
源码如下(我是采用一页显示10条记录):
需要四个文件
一个实体类文件 categoryinfomodel.cs
一个sqlhelper sqlhelper.cs
一个ajax服务端处理程序 pagedservice.ashx
一个客户端调用页面 wsxfy.htm
categoryinfomodel.cs和sqlhelper.cs我就不写了,都知道是什么文件
pagedservice.ashx 代码如下
复制代码 代码如下:
using system.web.script.serialization;
public void processrequest(httpcontext context)
{
context.response.contenttype = text/plain;
string straction = context.request[action];
//取页数
if (straction == getpagecount)
{
string strsql = select count(*) from categoryinfo;
int intrecordcount = sqlhelper.executescalar(strsql);
int intpagecount = intrecordcount / 10;
if (intrecordcount % 10 != 0)
{
intpagecount++;
}
context.response.write(intpagecount);
}//取每页数据
else if (straction == getpagedata)
{
string strpagenum = context.request[pagenum];
int intpagenum = convert.toint32(strpagenum);
int intstartrowindex = (intpagenum - 1) * 10 + 1;
int intendrowindex = (intpagenum) * 10 + 1;
string strsql = select * from ( select id,categoryname,row_number() over(order by id asc) as rownum from categoryinfo) as t;
strsql += where t.rownum >= + intstartrowindex + and t.rownum dataset ds = new dataset();
sqlconnection conn = sqlhelper.getconnection();
ds = sqlhelper.executedataset(conn, commandtype.text, strsql);
list categoryinfo_list = new list();//定义实体集合
for (int i = 0; i {
categoryinfomodel categoryinfo = new categoryinfomodel();
categoryinfo.categoryinfoid = convert.toint32(ds.tables[0].rows[i][id]);
categoryinfo.categoryname = ds.tables[0].rows[i][categoryname].tostring();
categoryinfo_list.add(categoryinfo);
}
javascriptserializer jss = new javascriptserializer();
context.response.write(jss.serialize(categoryinfo_list));//序列化实体集合为javascript对象
}
}
wsxfy.htm 代码如下
复制代码 代码如下:
无刷新分页
效果如下(页面好不好看取决于你画dom 的水平了,我这里只是简单的画了画)
其它类似信息

推荐信息