Jquery: ajax implements the new function of page turning without refreshing code _ jquery

Source: Internet
Author: User
Ajax page turning is common in practical applications. ajax page turning consists of two parts: js and html. For details, see the following, I hope it will not help you much. paste the Code directly:
Below is the js section:

The Code is as follows:


Var pageSize = "10"; // number of rows per page
Var currentPage = "1"; // current page
Var totalPage = "0"; // total number of pages
Var rowCount = "0"; // The total number of rows
Var params = ""; // Parameter
Var url = "activity_list.action"; // action
$ (Document). ready (function () {// The jquery code is loaded as the document is loaded.
// Query by PAGE
Function queryForPages (){
$. Ajax ({
Url: url,
Type: 'post ',
DataType: 'json ',
Data: "qo. currentPage =" + currentPage + "& qo. pageSize =" + pageSize + params,
Success: function callbackFun (data ){
// Parse json
Var info = eval ("(" + data + ")");
// Clear data
ClearDate ();
FillTable (info );
}
});
}
// Fill in data
Function fillTable (info ){
If (info. length> 1 ){
TotalPage = info [info. length-1]. totalPage;
Var tbody_content = ""; // No initialization string "", "undefined" by default"
For (var I = 0; I Tbody_content + =""
+""+ (I + 1 + (currentPage-1) * pageSize) +""
+""+ Info [I]. title. substr (0, 20) +""
+""+ Info [I]. address. substr (0, 6) +""
+""+ Info [I]. quota_sign +" person"
+""+ Info [I]. type +""
+"/Activity_edit.action? Id = "+ info [I]. id +" '> Edit"
+""
$ ("# T_body" ).html (tbody_content );
}
} Else {
$ ("# T_head" pai.html ("");
$ ("# T_body" pai.html ("

"+ Info. msg +"

");
}
}

// Clear data
Function clearDate (){
$ ("# T_body" ).html ("");
}

// Search Activity
$ ("# SearchActivity"). click (function () {queryForPages ();});
// Homepage
$ ("# FirstPage"). click (function (){
CurrentPage = "1 ";
QueryForPages ();
});
// Previous Page
$ ("# Previous"). click (function (){
If (currentPage> 1 ){
CurrentPage --;
}
QueryForPages ();
});
// Next page
$ ("# Next"). click (function (){
If (currentPage CurrentPage ++;
}
QueryForPages ();
});
// Last page
$ ("# Last"). click (function (){
CurrentPage = totalPage;
QueryForPages ();
});

});


The following is the html code:

The Code is as follows:
















Serial number Title Location Registered Category Operation

Homepage
Previous Page
Next Page
Last page

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.