MVC 之 Ajax 分页查询数据

前端之家收集整理的这篇文章主要介绍了MVC 之 Ajax 分页查询数据前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<span style="font-size:18px;">//分页控件
        $(document).ready(function () {
            var pageSize = 10;
            var index;
            //分页控件
            $.jqPaginator('#pagination2',{
                pageSize: pageSize,totalCounts: 10,//总条数
                visiblePages: 10,currentPage: 1,prev: '<li class="prev"><a href="javascript:;">上一页</a></li>',next: '<li class="next"><a href="javascript:;">下一页</a></li>',page: '<li class="page"><a href="javascript:;">{{page}}</a></li>',onPageChange: function (num,type) {
                    index = num;
                    getData();
                }
            });

            function getData() {
                $.post("@Url.Action("SelectBookStudent")",{
                    "pageSize": pageSize,"pageIndex": index,"type": "@(Request.QueryString["type"] ?? "False")"
                },function (result) {
                    var html = "";
                    if (result == null || result.list.length > 0) {
                        $('#pagination2').jqPaginator('option',{ totalCounts: result.total });
                        total = result.list.length;
                        $.each(result.list,function (i,item) {
                            //时间格式转换
                            var pa = /.*\((.*)\)/;
                            var StartDate = item.TKBeginDate.match(pa)[1].substring(0,10); //转换起始时间格式
                            var EndDate = item.TKEndDate.match(pa)[1].substring(0,10);//转换终止时间格式

                            var TKStartDate = getTime(StartDate); //起始日期
                            var TKEndDate = getTime(EndDate); //终止日期

                            var TKTestDate = TKStartDate.substring(0,10); //截取日期
                            var TKBeginTime = TKStartDate.substring(11,19); //截取起始时间
                            var TKEndTime = TKEndDate.substring(11,19);//终止时间

                            html += "<tr>";
                            html += "<td>" + (i + 1) + "</td>";
                            html += "<td>" + item.PlaceTest + "</td>";
                            html += "<td>" + TKTestDate + "</td>";
                            html += "<td>" + TKBeginTime + "</td>";
                            html += "<td>" + TKEndTime + "</td>";
                            html += "<td>" + item.RegNumTotal + "</td>";
                            html += "<td>" + item.RegNum + "</td>";
                            html += "<td>" + item.Explain + "</td>";
                            html += "<td><a href='javascript:void()' onclick='TKBook(\"" + item.TKCode + "\"," + item.Type + ")' >预约</a></td>";
                            html += "</tr>";

                        });
                        //$(".table-list tbody").html(html);
                        $("#select_tableList tbody").html(html);
                        $("#select_tableList tbody tr").click(function () { $(this).toggleClass("curr"); });
                        //$(".table-list tbody tr").click(function () { $(this).toggleClass("curr"); });
                    }
                })
            }
        });

    //时间转换 
 function getTime(/** timestamp=0 **/) {
 var ts = arguments[0] || 0;
 var t,y,m,d,h,i,s;
 t = ts ? new Date(ts * 1000) : new Date();
 y = t.getFullYear();
 m = t.getMonth() + 1;
 d = t.getDate();
 h = t.getHours();
 i = t.getMinutes();
 s = t.getSeconds();
 // 可根据需要在这里定义时间格式 
 return y + '-' + (m < 10 ? '0' + m : m) + '-' + (d < 10 ? '0' + d : d) + ' ' + (h < 10 ? '0' + h : h) + ':' + (i < 10 ? '0' + i : i) + ':' + (s < 10 ? '0' + s : s);
 }
</span>
原文链接:https://www.f2er.com/ajax/163004.html

猜你在找的Ajax相关文章