Ajax-implemented no-refresh paging code example:
Now everything is about a no refresh, even paging is the case, the following is from the network on a section of no refresh code, I hope to help everyone.
The code is as follows:
One. HTML code section:
<Tableclass= "Table Style-5"> <theadID= "T_head"> <TR> <th>Serial number</th> <th>Title</th> <th>Place</th> <th>Already enrolled</th> <th>Category</th> <th>Operation</th> </TR> </thead> <tbodyID= "T_body"> <!--Ajax Populate list -</tbody> </Table> <ButtonID= "FirstPage">Home</Button> <ButtonID= "Previous">Previous page</Button> <ButtonID= "Next">Next page</Button> <ButtonID= "Last">Last</Button>
Two. Ajax Code section:
varPageSize = "10";//number of rows per pagevarCurrentPage = "1";//Current PagevarTotalpage = "0";//Total PagesvarRowCount = "0";//total number of barsvarParams= "";//ParametersvarUrl= "Activity_list.action";//Action$ (document). Ready (function(){//The jquery code loads as the document loads //Paging Query functionqueryforpages () {$.ajax ({url:url, type:' Post ', DataType:' JSON ', Data:"Qo.currentpage=" +currentpage+ "&qo.pagesize=" +pagesize+params, success:functionCallbackfun (data) {//parsing JSON varinfo = eval ("(" +data+ ")"); //Clear Datacleardate (); Filltable (info); } }); } //Populating Data functionfilltable (info) {if(info.length>1) {Totalpage=info[info.length-1].totalpage; varTbody_content= "";//uninitialized string "", Default "undefined" for(vari=0;i<info.length-1;i++) {tbody_content+ = "<tr>" + "<TD data-title= ' serial number ' >" + (i+1+ (currentPage-1) *pagesize) + "</td>" + "<TD data-t Itle= ' title ' > ' +info[i].title.substr (0,20) + ' </td> ' + ' <td data-title= ' location ' > ' +info[i].address.substr (0,6 + "</td>" + "<td data-title= ' registered ' >" +info[i].quota_sign+ "People </td>" + "<td data-title= ' category ' & gt; " +info[i].type+ "</td>" + "<td data-title= ' operation ' ><a href= ' <%=request.getcontextpath ()%>/activity_ Edit.action?id= "+info[i].id+" > Edit </a></td> "+" </tr> " $("#t_body"). HTML (tbody_content); } } Else { $("#t_head"). HTML (""); $("#t_body"). HTML ("<div style= ' height:200px;width:700px;padding-top:100px; ' align= ' center ' >" +info.msg+ "</ Div> "); } } //Clear Data functionCleardate () {$ ("#t_body"). HTML (""); } //Search Activity$ ("#searchActivity"). Click (function() {queryforpages (); }); //Home Page$ ("#firstPage"). Click (function() {currentpage= "1"; Queryforpages (); }); //Previous Page$ ("#previous"). Click (function(){ if(currentpage>1) {currentpage-- ; } queryforpages (); }); //Next Page$ ("#next"). Click (function(){ if(currentpage<totalpage) {CurrentPage++ ; } queryforpages (); }); //last page$ ("#last"). Click (function() {currentpage=Totalpage; Queryforpages (); }); });
The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=8824
For more information, refer to: http://www.softwhy.com/jquery/
Ajax-implemented no-refresh paging code instance