ajax perfect implementation of the two page pagination function of the instance code

  • 2020-06-01 08:24:05
  • OfStack

Paginated front page

<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
<h1 align="center"> Pages of martial arts novels </h>
<script src="jquery-1.4.2.min.js"></script>
var page='';
  function init(page){
   var xhr;
 xhr = new XMLHttpRequest();
}else if(window.ActiveXObject){
 xhr =new ActiveXObject("Microsoft.XMLHTTP")
var url="fenye.php";
 else {xhr.send("page=1");}
 var content;
 function callback(){
      var json =eval('('+xhr.responseText+')');
  var fenye=json.str;
 //  alert(fenye);
  content="<th>ID</th><th> The name of the </th><th> The author </th><th> Press. </th><th>ISBN No. </th><th> type </th><th> The price </th>";
  for(var i=0;i<json.info.length;i++){
    // alert(fenye);


<body onLoad="init()">
 <h3 align="center">jquery implementation $.ajax paging </h3>
<table id="tables" style=" width:500px; height:100px; text-align:center" align="center" border="5" bordercolor="#FF6600">
<th>ID</th><th> The name of the </th><th> The author </th><th> Press. </th><th>ISBN No. </th><th> type </th><th> The price </th>
<table align="center" style="margin-top:15px">
 <td style="colspan:3;height:20">
 <div id="div" style="position:absolute; left: 447px; top: 218px; width: 411px; height: 22px;"></div>
<br />

Paging php essence code

    // The command model layer processes the data 
  $link=mysql_connect('localhost','root','') or die(" failure ");
  mysql_select_db('books',$link) or die(" Connection to database error! ");
  // Displays the number of records per page 
  $pagesize = 2;
  // Find the total number of records 
  $sql = "select count(*) as total_rows from books";
  $result = mysql_query($sql);
  $total_rows = mysql_fetch_array($result);
  // Find the total number of pages 
  $pages = ceil($total_rows[0]/$pagesize);
  // Current page 
  $page = $_POST['page'];
  $strtext = " The current first ".$page." page "." In total, ".$pages." page "." A total of ".$total_rows[0]." record ";
  // Next, I'm going to figure out the corresponding number based on the page that I'm currently clicking on 
  $offset = $pagesize*($page-1);
  $sql = "select * from books limit $offset,$pagesize";
  mysql_query("set names utf8");

  $pageInfo = $rows;
  //echo json_encode($pageInfo);
  // The data link will be obtained and returned 

  // The command view layer displays the data 
      $first_a = "<a onclick='init(".$first.")' href='#'><img src='3.jpg' width='50px;' height='20px;'/></a>";
   $prev_a = "<a onclick='init(".$prev.")' href='#'><img src='1.jpg' width='50px;' height='20px;'/></a>";
   $next_a = "<a onclick='init(".$next.")' href='#'><img src='2.jpg' width='50px;' height='20px;'/></a>";
  $last_a = "<a onclick='init(".$last.")' href='#'><img src='4.jpg' width='50px;' height='20px;'/></a>";
  @$str = $strtext.$first_a.$prev_a.$next_a.$last_a;
  $info = array('str'=>$str,'info'=>$pageInfo);
  echo json_encode($info);

Related articles: