Get the App
SLTechnology News&Howtos  ›  Network Security  › 

Ajax pagination complete code finishing

Shulou Source: shulou.com Published: 2022-06-01 05:03:14 10月04日 Update

/ * ajax pagination * / var page_cur = 1; / / current page var total_num, page_size, page_total_num / / Total records, pages per page, total pages function getData (page) {/ / get current page data $.ajax ({type: 'GET', url: processing data address, data: {' page': page, 'catid':' {$video_info.catid}'}, dataType: 'json' Success: function (json) {$("# ul_lists") .empty () Total_num = json.total_num; / / Total records page_size = json.page_size; / / number of pages per page page_cur = page; / / current page page_total_num = json.page_total_num; / / total pages var li = "; var list = json.list $.each (list, function (index, array) {/ / traversal returns json var curid = {$video_info.id}; var cur = curid = = array ['id']? "class='cur'": "; li + ="+ array ['title'] +" + array [' time'] + ";}); $(" # ul_lists ") .append (li);}, complete: function () {getPageBar () / / js generates pagination, can be replaced by program}, error: function () {alert ("data exception, please check whether json format";}});} function getPageBar () {/ / js generate paging if (page_cur > page_total_num) page_cur = page_total_num; / / the current page is greater than the maximum number of pages if (page_cur)

< 1) page_cur = 1; //当前页小于1 page_str = "共" + total_num + "条" + page_cur + "/" + page_total_num + ""; if(page_total_num >

1) {if (page_cur = = 1) {/ / if the first page page_str + = "Home page previous";} else {page_str + = "Home page previous";} if (page_cur > = page_total_num) {/ / if the last page page_str + = "next last page" } else {page_str + = "next last page";} $("# page") .html (page_str);} $(function () {getData (1)) / / default first page $("# page a") .live ('click', function () {/ / live adds event handlers to future elements, not available bind var page = $(this) .attr ("data-page"); / / get the current page getData (page)});})

The data processor queries the data for the normal receiving parameters and then returns to the json foreground for processing.

Tags: Data processing number of pages components if yes previous home maximum event element foreground parameters address processor data processing quantity format program query check Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Huawei Shulou Tech Info macOS Shulou Technology