php ajax ashx, jQuery_Jquery Ajax.ashx efficient paging implementation code, I used to use UpdatePanel Upd - phpStudy...

Jquery Ajax.ashx efficient paging implementation code

In the past, I was used to using UpdatePanel UpdateProgress and other controls, and even to the extent of abuse, I just blindly pursued no refresh, while making this loading picture prompt, which seems to be more beautiful, but it feels more loss of performance, and sometimes it also destroys Integrity of the website.

But after learning Jquery, I learned about Jquery.ajax, Jquery.get and other methods, so I learned to use webservice and .ashx files to interact with the server.

This time the Jquery pagination is matched with the .ashx file.

Create three .ashx, PreviewHandler.ashx, PageHandler.ashx, NextHandler.ashx, respectively, to process the current page, the next page, and the previous page.

PageHandler.ashx

Copy the code The code is as follows:

public void ProcessRequest(HttpContext context)

{

context.Response.ContentType = "text/plain";

IQueryable answer = xt.Answer.Take(10);

StringBuilder sb = new StringBuilder();

sb.Append("

answer content answer username creation time

foreach (Answer a in answer)

{

sb.Append("

" + a.Answer_content + "" + a.Answer_UserName + "" + a.Answer_Creatime + "");

}

sb.Append("

");

context.Response.Write(sb);

}

NextHandler.ashx

Copy the code The code is as follows:

public void ProcessRequest(HttpContext context)

{

context.Response.ContentType = "text/plain";

int RowCount = 10;

int Current = Convert.ToInt32(context.Request.Params["index"]) + 1;

IQueryable answer = xt.Answer.Skip(RowCount * (Current - 1)).Take(RowCount);

StringBuilder sb = new StringBuilder();

sb.Append("

answer content answer username creation time

foreach (Answer a in answer)

{

sb.Append("

" + a.Answer_content + "" + a.Answer_UserName + "" + a.Answer_Creatime + "");

}

sb.Append("

");

context.Response.Write(sb);

}

PreviewHandler.ashx

Copy the code The code is as follows:

public void ProcessRequest(HttpContext context)

{

context.Response.ContentType = "text/plain";

int RowCount = 10;

int Current = Convert.ToInt32(context.Request.Params["index"]) - 1;

IQueryable answer = xt.Answer.Skip(RowCount * (Current - 1)).Take(RowCount);

StringBuilder sb = new StringBuilder();

sb.Append("

answer content answer username creation time

foreach (Answer a in answer)

{

sb.Append("

" + a.Answer_content + "" + a.Answer_UserName + "" + a.Answer_Creatime + "");

}

sb.Append("

");

context.Response.Write(sb);

}

In fact, most of the three files have similar codes, and then they are called through html or aspx files, using Jquery.get()

Copy the code The code is as follows:

var Init=function(){

$.get("PageHandler.ashx",function(data){

document.getElementById('content').innerHTML=data;

$('.currIndex').attr('value',"1");

document.getElementById("PageInfo").innerHTML="当前第1页";

});

}

var Preview=function(){

var current=$('.currIndex').attr('value');

var pre=Number(current)-1;

$.get("PreviewHandler.ashx",{index:current},function(data){

document.getElementById('content').innerHTML=data;

$('.currIndex').attr('value',pre);

document.getElementById("PageInfo").innerHTML="当前第"+pre+"页";

});

}

var Next=function(){

var current=$('.currIndex').attr('value');

var next=Number(current)+1;

$.get("NextHandler.ashx",{index:current},function(data){

document.getElementById('content').innerHTML=data;

$('.currIndex').attr('value',next);

document.getElementById("PageInfo").innerHTML="当前第"+next+"页";

});

}

调用.ashx文件生成的数据即可,点击下一页,将NextHandler.ashx文件的内容覆盖PageHandler.ashx文件内容。

结果如图:

有待解决的问题是,对这些行进行编辑,我在.ashx文件加了 一个

而且在.aspx文件上也写了del 方法,但是会报错, object expected error ,这个错误,应该是找不到 del方法吧,他们的生成时间,不懂,还未解决,

谁能解决可以告诉我。。。相关阅读:

浅谈在ASP.NET中数据有效性校验的方法

CSS高级技巧之圆角矩形下

HTML标记语言——表单

探秘Discuz!NT2.5之社区辩论贴功能

教你用dedecms快速制作电影站点

Linux下将.cue/.bin转换为.iso的方法

Windows系统进程轻松管理的小工具

Oracle与MySQL删除字段时的处理对照

js下判断 iframe 是否加载完成的完美方法

MSSQL 将截断字符串或二进制数据问题的解决方法

“增强js程序代码的健壮性”之我见大量示例代码

asp.net中Response.Redirect与Server.Transfer的区别分析

利用CSS的媒体类型满足访客需求

Windows 窗体的.Net 框架绘图技术

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324507641&siteId=291194637