AJAX is a technique for exchanging data with a server that can update a part of a Web page without re-loading the entire page. This article mainly introduces the non-refresh page code of PHP implemented by using AJAX.
<?php Header ("content-type:text/html; Charset=utf-8 "); function Ajaxpage ($Total, $ListNub, $CurrentPage, $Url, $AjaxAction, $HalfPer = ", $ViewId =") {//Count total pages $totalPage = @ceil ($Total/$ListNub); $total = $totalPage-1; $re = ""; Echo $CurrentPage; $re. = ($CurrentPage > 0)? "<td><a href=\" javascript: $AjaxAction (' $Url =0 ', ' $ViewId ') \ "\" > Home </a></td>\n<td> <a href=\ "javascript: $AjaxAction ('". $Url. " =". ($CurrentPage-1). "', ' $ViewId ') \" \ "> Prev </a></td>\n": "<td> home </td>\n<td> Previous </ Td>\n "; for ($i = $CurrentPage-$HalfPer, $i > 0 | | $i = 0, $j = $CurrentPage + $HalfPer, $j < $totalPage | | $j = $t Otalpage, $i < $j, $i + +) {$re. = $i = = $CurrentPage? "<td><b class=currentpage>[". ($i + 1). "]</b></td>\n": "<td><a href=\" javascript: $AjaxAction (' $Url = $i ', ' $ViewId ') \ ">". ($i + 1). "</a></td>\n"; } $re. = ($CurrentPage < $total)? "<tD><a href=\ "javascript: $AjaxAction ('". $Url. " =". ($CurrentPage + 1). "', ' $ViewId ') \" \ "> next page </a></td>\n<td><a href=\" javascript: $AjaxAction (' ". $Url." =". ($total). "', ' $ViewId ') \" \ "> Last </a>\n</td>": "<td> next </td>\n<td> last </td>\n" ; $re = "<table style=text-align:center><tr> $re </tr></table>"; return $re; }//Total pages, passed page variables-how many pages before and after the URL address of the current page $page = $_get[' page '); Echo page (' Ten ', $page, ' index.php?page ', ' 2 ');?> <p id= "Nike" > <?php echo ajaxpage (200,20, $page, ' rand.php ? page ', ' ajaxaction ', ' 2 ', ' Nike ');?> </p> <script type= "Text/javascript" language= "JavaScript" > var Http_request = false; function Send_request (url,htmlid) {http_request = False, if (window). XMLHttpRequest) {http_request = new XMLHttpRequest (); if (http_request.overridemimetype) {http_request.overridemimetype (' text/xml '); }} else if (window. ActiveXObject) {try {http_request = new ActiveXObject("Msxml2.xmlhttp"); } catch (e) {try {http_request = new ActiveXObject ("Microsoft.XMLHTTP"); } catch (E) {}}} if (!http_request) {alert (' Cannot create XMLHttpRequest Object! '); return false; } Http_request.onreadystatechange = function () {Likeakak (htmlid);} ProcessRequest (htmlid) http_request.open (' GET ', url, true); Http_request.send (NULL); }//Processing return information function ProcessRequest (htmlid) {if (http_request.readystate = = 1) {document.getElementById (htmlid). Inner html= "Download ..."; } if (http_request.readystate = = 4) {if (Http_request.status = =) {document.getElementById (htmlid). innerhtml=h Ttp_request.responsetext; } else {alert (' request exception '); }}}//Processing return information function Likeakak (htmlid) {if (http_request.readystate = = 1) {document.getElementById (htmlid). Innerht ml= "Download ..."; } if (http_request.readystate = = 4) {if (Http_request.status = =) {document.getElementById (htmlid). innerhtml=h Ttp_request.responsetext; } else {alert (' request exception '); } } } function Ajaxaction (url,viewid) {send_request (URL,VIEWID);}//Custom calling functions Elist (ID) {var inputarray = new Array (); INPUTARRAY[1] = ' AAA '; INPUTARRAY[2] = ' BBB '; INPUTARRAY[3] = ' CCC '; INPUTARRAY[4] = ' DDD '; INPUTARRAY[5] = ' eee '; Send_request (' ajax.php?do=ajax&sort= ' +id,inputarray[id]); } </script>