Jquery:ajax implementation page without refreshing function code _jquery

Source: Internet
Author: User
Not much to say, directly paste code:
Here is the JS section:
Copy Code code as follows:

var pageSize = "10";//number of rows per page
var currentpage = "1";//Current page
var totalpage = "0";//Total pages
var rowcount = "0";//total number of bars
var params= "";//Parameter
var url= "Activity_list.action";//action
$ (document). Ready (function () {//jquery code loaded with document loaded
Page-Search
function Queryforpages () {
$.ajax ({
Url:url,
Type: ' Post ',
DataType: ' JSON ',
Data: "qo.currentpage=" +currentpage+ "&qo.pagesize=" +pagesize+params,
Success:function Callbackfun (data) {
Parsing JSON
var info = eval ("+data+"));
Emptying data
Cleardate ();
Filltable (info);
}
});
}
Populating data
function Filltable (info) {
if (info.length>1) {
Totalpage = Info[info.length-1].totalpage;
var tbody_content= "";//Do not initialize string "", Default "undefined"
for (var i=0; i<info.length-1;i++) {
Tbody_content = "<tr>"
+ "&LT;TD data-title= ' serial number ' >" + (i+1+ (currentPage-1) *pagesize) + "</td>"
+ "<td data-title= ' title ' >" +info[i].title.substr (0,20) + "</td>"
+ "<td data-title= ' place ' >" +info[i].address.substr (0,6) + "</td>"
+ "<td data-title= ' has enrolled ' >" +info[i].quota_sign+ "Person </td>"
+ "<td data-title= ' category ' >" +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> ");
}
}

Emptying data
function Cleardate () {
$ ("#t_body"). HTML ("");
}

Search activity
$ ("#searchActivity"). Click (function () {queryforpages ();});
Home
$ ("#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
$ ("#last"). Click (function () {
CurrentPage = Totalpage;
Queryforpages ();
});

});

Here is the HTML code section:
Copy Code code as follows:

<table class= "Table style-5" >
<thead id= "T_head" >
< tr>
<th> serial </th>
<th> title </th>
<th> location </th>
<th> signed </t h>
<th> category </th>
<th> operation </th>
</tr>
</thead>
<tbody I d= "T_body" >
<!--ajax populate list-->
</tbody>
</table>
<button id= "FirstPage" > Home </button>
<button id= "Previous" > Prev </button>
<button id= "Next" > next page </button >
<button id= "Last" > End </button>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.