Ajax无刷新分页

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>

</head>
<body>
<ul id="ulcomment"></ul>
<table>
<tr id="trPage"></tr>
</table>
<script type="text/javascript">
    $.post("PagedService.ashx", { "action": "getpagecount" }, function (data, status) {
        for (var i = 1; i <= data; i++) {
            var td = $("<td> <a href=‘‘>" + i + "</a></td>");
            $("#trPage").append(td);
        }

        $("#trPage td").click(function (e) {

            e.preventDefault(); //不要超链接起作用
            $.post("PagedService.ashx", { "action": "getpagedata", "pagenum": $(this).text() },
                function (data, status) {
                    var comments = $.parseJSON(data);

                    $("#ulcomment").empty();
                    for (var i = 0; i < comments.length; i++) {
                        var comment = comments[i];

                        var li = $("<li>提交时间:" + comment.PostDate + "评论" + comment.Msg + "</li>");
                        $("#ulcomment").append(li);
                    }
                });
        });
    });
       $.post("PagedService.ashx", { "action": "getpagedata", "pagenum": "1" },//初始化的默认第一页
                function (data, status) {
                    var comments = $.parseJSON(data);

                    $("#ulcomment").empty();
                    for (var i = 0; i < comments.length; i++) {
                        var comment = comments[i];

                        var li = $("<li>提交时间:" + comment.PostDate + "评论" + comment.Msg + "</li>");
                        $("#ulcomment").append(li);
                    }
                })

    </script>
</body>

</html>

  

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Ajax翻页.DAL.DataSetCommentTableAdapters;
using System.Web.Script.Serialization;

namespace Ajax翻页
{
    /// <summary>
    /// PagedService 的摘要说明
    /// </summary>
    public class PagedService : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string action = context.Request["action"];
            if (action=="getpagecount")
            {
                var adapter = new T_CommentsTableAdapter();
                int count = adapter.SelectCount().Value;
                int pagecount = count / 10;
                if (count%10!=0)
                {
                    pagecount++;
                }
                context.Response.Write(pagecount);
            }
            else if (action == "getpagedata")
            {
                string getpagedata = context.Request["pagenum"];//获得传过来的页数
                int IPageNUm = Convert.ToInt32(getpagedata);
                var adapter = new T_CommentsTableAdapter();//获得adapter
                var data = adapter.GetPagedData((IPageNUm - 1) * 10 + 1, (IPageNUm) * 10);//根据页数获得数据
                List<Comment> list = new List<Comment>();//创建list
                foreach (var item in data)//在list中循环输入Comment属性PostDate,Msg
                {
                    list.Add(new Comment() { PostDate = item.PostDate.ToShortDateString(), Msg=item.Msg });
                }
                JavaScriptSerializer jss = new JavaScriptSerializer();//序列化list为json
                context.Response.Write(jss.Serialize(list));
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
    public class Comment
    {
        public string PostDate { get; set; }
        public string Msg { get; set; }
    }
}

  

select *from(
SELECT Id, PostDate, Msg,Row_Number()over(order by PostDate)rownum FROM dbo.T_Comments
)t
where t.rownum>[email protected] and t.rownum<@endRowIndex

Ajax无刷新分页

时间: 2024-08-11 05:42:08

Ajax无刷新分页的相关文章

ajax无刷新分页类

<?php  class Page {   // 分页栏每页显示的页数 public $rollPage = 10; // 页数跳转时要带的参数 public $parameter; // 默认列表每页显示行数 public $listRows = 20; // 起始行数 public $firstRow; // 分页总页面数 protected $totalPages; // 总行数 protected $totalRows; // 当前页数 protected $nowPage; // 分页

jquery+jquery.pagination+php+ajax 无刷新分页

<!DOCTYPE html> <html ><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>预约列表</title> <link rel="stylesheet" href="./static/pagination.css"> &

ThinkPhp 3.2 ajax无刷新分页(未完全改完,临时凑合着用)

临时更改后的page类(很多地方没修改...因为笔者PHP没学好..)如下: <?phpnamespace Fenye\libs; /**  file: page.class.php   完美分页类 Page  */ class Page {  private $total;          //数据表中总记录数  private $listRows;       //每页显示行数  private $limit;          //SQL语句使用limit从句,限制获取记录个数  pri

SUI分页组件和avalon搞定ajax无刷新分页

<div ms-controller="main"> <h2 class="pagination-centered">{{ title }}</h2> <form method="get" action="" class="sui-form" style="margin-bottom:5px;"> 重量:<input class=&q

Ajax实现无刷新分页

注:本文中使用到的一些类库在前面文章都能找到源代码,我会在文中指明链接所在,为了缩短文章篇幅,由此带来的阅读不便,敬请谅解. 本文讲解 Ajax 实现无刷新分页.实现原理.代码展示.代码下载. 这里需要说明一些知识: 1.Ajax 无刷新页面的好处:提供良好的客户体验,通过 Ajax 在后台从数据库中取得数据并展示,取缔了等待加载页面而出现的空白状态: 2.那么,Ajax 无刷新页面是运行在动态页面(.PHP)?还是静态页面(.html/.htm/.shtml)?答案是:静态页面: 3.实现原理

在Thinkphp中使用AJAX实现无刷新分页

在Thinkphp目录的Lib\ORG\Util\目录里新建AjaxPage.class.php,写入一下内容: <?php // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK IT ] // +---------------------------------------------------------------

TinkPHP_无刷新分页_未带搜索条件

1)前台显示模板: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Ajax 实现无刷新页面</title> <meta http-equiv="Content-Type" conte

Ajax 实现无刷新分页

Ajax 实现无刷新分页

smarty+php+ajax 简单无刷新分页

简介 分页,无非就是从数据库中获得我们想查询的数据,再加以处理即可! ① 确定数据总数($count) ② 每页显示数据条数($pageSize) ③ 分多少页($pageCount) ④ 上一页($pagePrev) ⑤ 下一页($pageNext) ⑥ 判断越界问题 ⑦ 偏移量($offset) ⑧ sql语句($sql = "select * from goods limit $offset,$pageSize";) 简单归简单,我们还得考虑实际的应用.例如:如果你正在土豆网看&