Home > Web Front-end > JS Tutorial > jQuery getJSON() .ashx implements paging (improved version)_jquery

jQuery getJSON() .ashx implements paging (improved version)_jquery

WBOY
Release: 2016-05-16 17:38:58
Original
1337 people have browsed it

Reference: http://www.jb51.net/article/35110.htm
Improvements:
1. ashx returns json data, reducing the amount of transmitted data, and html page style control It is also more flexible;
2. Rewrite the jQuery code of the html page;
3. Simplify 3 ashx files into 1.
1. Create test data for the table:

Copy the code The code is as follows:

create table test(id int identity,title varchar(36))
declare @index int;
set @index = 1;
while(@index < 8888)
begin
insert test(title) values ​​(newid())
set @index = @index 1
end

2. .html page
Copy code The code is as follows:








< form id="form1" runat="server">









The code is as follows:

四、效果
jQuery getJSON() .ashx implements paging (improved version)_jquery 
--------------------------------------------------------------------------------------------------------------------
备注 (2010-7-10):
用sql2005 row_number()分页方法,.ashx页面代码可简化为
复制代码 代码如下:

public class Handler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
DataBase db = new DataBase();
int pageSize = 10;
int pageIndex = 0;
int.TryParse(context.Request.Params["index"], out pageIndex);
string type = context.Request.Params["type"];
string sql = string.Format("select * from ( select row_number() over (order by id) as rowNum,* from test) as t "
" where rowNum>{0} and rowNum<={1}", pageIndex * pageSize, (pageIndex 1) * pageSize);
DataTable dt = db.GetDataSet(sql, null).Tables[0];
context.Response.Write(JSONHelper.DataTableToJSON(dt));
}
public bool IsReusable
{
get
{
return false;
}
}
}

备注
其中JSONHelper.DataTableToJSON(dt)方法为DataTable解析成JSON,见另一篇文章JSONHelper帮助类
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template