PHP + AJAX implementation of refreshing pagination

Source: Internet
Author: User
Tags learn php programming
This article mainly introduces the implementation method of PHP + AJAX refreshing pagination. For more information about the code of PHP + AJAX refreshing pagination, see the ajax tutorial, I want to write a simple entry-level PHP + AJAX without refreshing pages. based on the ajax development framework, the code is as follows:

Var http_request = false; function send_request (url) {// initialization, specifies the processing function, and the request sending function http_request = false; // starts to initialize the XMLHttpRequest object if (window. XMLHttpRequest) {// Mozilla http_request = new XMLHttpRequest (); if (http_request.overrideMimeType) {// Set the MIME category http_request.overrideMimeType ("text/xml");} else if (window. activeXObject) {// IE browser try {http_request = new ActiveXObject ("Msxml2.XMLHttp");} catch (e) {try {http_request = new ActiveXobject ("Microsoft. XMLHttp");} catch (e) {}} if (! Http_request) {// exception. failed to create the object instance window. alert ("failed to create the XMLHttp object! "); Return false;} http_request.onreadystatechange = processrequest; // Determine the request sending method, URL, and whether to synchronously execute the following code http_request.open (" GET ", url, true ); http_request.send (null);} // function processrequest () {if (http_request.readyState = 4) {// judge the object status if (http_request.status = 200) {// The information has been returned successfully. start to process the information document. getElementById (reobj ). innerHTML = http_request.responseText;} else {// The page is not normal alert ("the page you requested is not normal! ") ;}} Function dopage (obj, url) {document. getElementById (obj ). innerHTML = "reading data... "; send_request (url); reobj = obj ;}

I put the content in a p display. when the page flip action is generated, I use AJAX to update the DIV to achieve the page flip effect. this is the page code for displaying the content:

 Ajax paging demonstration
 

". ($ Total? ($ Offset + 1): 0 )."-". Min ($ offset + 10, $ total )."Records, total $ total records "; // if there is only one page, the function will jump out: if ($ pagenum <= 1) return false; $ pagenav. = "homepage"; if ($ prepg) $ pagenav. = "previous page"; else $ pagenav. = "previous page"; if ($ nextpg) $ pagenav. = ""; else $ pagenav. = "back page"; $ pagenav. = "Last page"; $ pagenav. ="Page, total $ pagenum page "; // If the incoming page number parameter is greater than the total page number, the Error message If ($ page> $ pagenum) {Echo" Error: can Not Found The page ". $ page; Exit;} $ info = mysql_query ("select * from cr_userinfo limit $ offset, $ num "); // obtain the data to be displayed for the corresponding page number While ($ it = mysql_fetch_array ($ info) {Echo $ it ['username']; echo"
";}// Display data echo"
"; Echo $ pagenav; // output paging navigation?>

The key to page turning is to call the dopage () function during page turning, and then use the callback information to update the content in p. The core code on the server side is as follows:

 ". ($ Total? ($ Offset + 1): 0 )."-". Min ($ offset + 10, $ total )."Records, total $ total records "; // if there is only one page, the function will jump out: if ($ pagenum <= 1) return false; $ pagenav. = "homepage"; if ($ prepg) $ pagenav. = "previous page"; else $ pagenav. = "previous page"; if ($ nextpg) $ pagenav. = ""; else $ pagenav. = "back page"; $ pagenav. = "Last page"; $ pagenav. ="Page, total $ pagenum page "; // If the incoming page number parameter is greater than the total page number, the Error message If ($ page> $ pagenum) {Echo" Error: can Not Found The page ". $ page; Exit;} $ info = mysql_query ("select * from cr_userinfo limit $ offset, $ num "); // obtain the data to be displayed for the corresponding page number While ($ it = mysql_fetch_array ($ info) {Echo $ it ['username']; echo"
";}// Display data echo"
"; Echo $ pagenav; // output paging navigation?>

The above explains in detail the implementation of PHP + AJAX without refreshing pages, hoping to help you learn php programming.

For more details about the implementation of PHP + AJAX refreshing pagination methods, please follow the PHP Chinese network!

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.