How to implement Ajax paging without refreshing

php中世界最好的语言
Release: 2018-04-04 13:37:35
Original
1011 people have browsed it

This time I will show you how to implement Ajax paging without refreshing, and what are theprecautions to implement Ajax paging without refreshing. The following is a practical case, let's take a look.

Following the previous article - Java+Oracle code to implement paging (2) on the principles and implementation of paging technology, this article continues to analyze paging technology. The previous article talked about the code implementation of paging technology. This article continues to analyze the effect control of paging technology.

In the previous article, we have simply implemented a paging using code. But we have all seen that every time the result set is obtained through the servlet request in the code, it will be redirected to a jsp page to display the results, so that the page will be refreshed every time the query appears. For example, after querying the result set and looking at the third page, the page will be Will refresh it. The effect of this page will be a bit uncomfortable, so we hope that no matter which page is accessed after querying the result set through conditions, the page will not be refreshed, but only the result set will change. To solve this, I think everyone will easily think of Ajax.
Yes, we have to ask Ajax to come out. After the result set is queried through the query conditions, every subsequent visit to any page will be accessed through Ajax. Asynchronous Ajax is used to interact with the Servlet, and the results are queried and returned to Ajax. In this way, the page content changes because Ajax returns the results, and The page will not be refreshed, which implements refresh-free paging technology.
Let’s take a look at a simple non-refresh paging implementation. The code is as follows:

     JavaScript" src="../lib/jQuery/jquery.min.js" mce_src="lib/jquery/jquery.min.js">    Pagination 

jQuery Pagination Plugin Demo


This content will be replaced when pagination inits.

Globally maximize granular "outside the box" thinking vis-a-vis quality niches. Proactively formulate 24/7 results whereas 2.0 catalysts for change. Professionally implement 24/365 niches rather than client-focused users.

Competently engineer high-payoff "outside the box" thinking through cross functional benefits. Proactively transition intermandated processes through open-source niches. Progressively engage maintainable innovation and extensible interfaces.

Credibly fabricate e-business models for end-to-end niches. Compellingly disseminate integrated e-markets without ubiquitous services. Credibly create equity invested channels with multidisciplinary human capital.

Interactively integrate competitive users rather than fully tested infomediaries. Seamlessly initiate premium functionalities rather than impactful architectures. Rapidiously leverage existing resource-leveling processes via user-centric portals.

Monotonectally initiate unique e-services vis-a-vis client-centric deliverables. Quickly impact parallel opportunities with B2B bandwidth. Synergistically streamline client-focused infrastructures rather than B2C e-commerce.

Phosfluorescently fabricate 24/365 e-business through 24/365 total linkage. Completely facilitate high-quality systems without stand-alone strategic theme areas.

Copy after login
This is a very simple non-refresh paging implementation, using the JQuery+ jquery.pagination framework. Now with the popularity of frameworks, especially the popularity of Jquery, it is very effective to use frameworks for development. The above code principle has been commented in the code. You can also refer to Jquery's official website:.

Now we can develop our Ajax non-refresh paging implementation. Based on the above principle, in pageselectCallback() in the code that responds to the page number being pressed, we use an Ajax to asynchronously access the database, take out the result set through the clicked page number, and then set it to the page asynchronously, so that no refresh can be completed accomplish.

The response function pageselectCallback() when the page number is pressed is modified as follows:

In this way, the results can be obtained asynchronously and the showResponse function is used to process the results. The showResponse function is as follows:

function showResponse(request){ var content = request; var root = content.documentElement; var responseNodes = root.getElementsByTagName("root"); var itemList = new Array(); var pageList=new Array(); alert(responseNodes.length); if (responseNodes.length > 0) { var responseNode = responseNodes[0]; var itemNodes = responseNode.getElementsByTagName("data"); for (var i=0; i 0 && nameNodes.length > 0&&sexNodes.length > 0&& ageNodes.length > 0) { var id=idNodes[0].firstChild.nodeValue; var name = nameNodes[0].firstChild.nodeValue; var sex = sexNodes[0].firstChild.nodeValue; var age=ageNodes[0].firstChild.nodeValue; itemList.push(new Array(id,name, sex,age)); } } var pageNodes = responseNode.getElementsByTagName("pagination"); if (pageNodes.length>0) { var totalNodes = pageNodes[0].getElementsByTagName("total"); var startNodes = pageNodes[0].getElementsByTagName("start"); var endNodes=pageNodes[0].getElementsByTagName("end"); var currentNodes=pageNodes[0].getElementsByTagName("pageno"); if (totalNodes.length > 0 && startNodes.length > 0&&endNodes.length > 0) { var total=totalNodes[0].firstChild.nodeValue; var start = startNodes[0].firstChild.nodeValue; var end = endNodes[0].firstChild.nodeValue; var current=currentNodes[0].firstChild.nodeValue; pageList.push(new Array(total,start,end,current)); } } } showTable(itemList,pageList); }
Copy after login
The above code is used to process the results in XML format returned after asynchronously requesting the Servlet through Ajax. The Servlet code is in the previous article. Among them, itemList and pageList are the user List and paging navigation generated after parsing and returning respectively, so that users can display data in their own way.

function pageselectCallback(page_index, jq){ var pars="pageNo="+(page_index+1); $.ajax({ type: "POST", url: " UserBasicSearchServlet", cache: false, data: pars, success: showResponse }); return false; }
Copy after login
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

How does AjaxToolKit use the Rating control

How does jQuery+ajax implement json data traversal

The above is the detailed content of How to implement Ajax paging without refreshing. For more information, please follow other related articles on the PHP Chinese website!

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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!