Paging technology principle and implementation-no-refreshing Ajax paging technology (III), ajax Paging
Next, go to the previous article-paging technology principles and implementation-Java + Oracle code implementation page (2). This article continues to analyze paging technology. The previous article describes code implementation of paging technology. This article further analyzes the effect control of paging technology.
The previous article has implemented a page by simple code. However, we can see that every time the result set is obtained through the servlet request in the Code, the result is directed to a jsp page to display the result, so that each query page will be refreshed, for example, if you want to view the third page after the result set appears in the query, the page will be refreshed. In this way, the page may feel a little uncomfortable, so we hope that the page will not be refreshed no matter which page is accessed after the result set is queried through the condition, the result set changes. To solve this problem, I think it's easy for everyone to think about Ajax.
Yes, this requires Ajax to go out of the mountains. After a result set is queried through the query condition, Ajax is used to access any page each time. asynchronous Ajax is used to interact with the Servlet and the result is returned to Ajax, in this way, the page content changes because Ajax returns results, but the page will not be refreshed, which implements the paging technology without refreshing.
Next we will look at a simple implementation of refreshing pagination. The Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Strict // EN "" http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd "> <Html xmlns =" http://www.w3.org/1999/xhtml "Xml: lang =" en ">
This is a very simple implementation of refreshing pages, using the JQuery + jquery. pagination framework. With the popularity of frameworks, especially Jquery, It is very effective to use frameworks for development. The above Code principles have been commented out in the code. You can also refer to the official Jquery Website :.
Now we can develop our Ajax implementation without refreshing pages. Based on the above principle, in the Code pageselectCallback () in which the response page number is pressed, we use Ajax to access the database asynchronously, retrieve the result set by clicking the page number, and then asynchronously set it to the page, in this way, the non-Refresh implementation can be completed.
Modify the response function pageselectCallback () that is pressed on the page number as follows:
In this way, you can obtain the result asynchronously and use the showResponse function to process the result. 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<itemNodes.length; i++) { var idNodes = itemNodes[i].getElementsByTagName("id"); var nameNodes = itemNodes[i].getElementsByTagName("name"); var sexNodes=itemNodes[i].getElementsByTagName("sex"); var ageNodes=itemNodes[i].getElementsByTagName("age"); if (idNodes.length > 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); }
The above code is used to process the XML format results returned after the Servlet is requested asynchronously through Ajax. The Servlet code is in the previous article. Here, itemList and pageList are the user List and paging navigation generated after resolution and return, 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;}
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.