PHP Ajax No refresh paging, support ID location sample code

Source: Internet
Author: User
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>

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.