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!