search
Homephp教程php手册php ajax 分页二

php ajax 分页二

Jun 13, 2016 am 11:21 AM
ajaxaspasp.netjavajqueryjspphptwoPaginationrefresh

ajax分页   php ajax 分页   java ajax分页   asp.net ajax分页   jquery ajax 分页 jsp ajax无刷新分页   asp ajax分页   ajax 分页问题   ajax实现分页   ajax jsp分页
下面接着上一篇文件来看page.js的代码,

var Page = {
 url:'',//URL地址
 method:'GET',
 display:'',//分页显示方法Default || Default2 || 也可以自定义
 Plugins:'', //返回JSON数据,需要用此函数格式化 需自定义函数
 pagediv:'', //分页字符显示的DIV
 index:'[第一页]',
 lastpage:'[上一页]',
    nextpage:'[下一页]',
 endpage:'[最尾页]',
 lastten:'[上10页]',
 nextten:'[下10页]', 
 javascript:'Page.Open',//很郁闷吧~函数名
 Send: function(method,url,pars,fun) {// Ajax连接初始化
  new Ajax.Request( url,{method: method, parameters: pars, onComplete: eval('this.Result')});
 },
 Open: function(pageno){
  SetCookie('pageno',pageno);
  pars='pageno='+pageno;
  url=this.url;
  fun=this.display;
  method=this.method;
  Page.Send(method,url,pars,fun); 
 },
 Init:function(url,options){
  this.url=url;
  this.display=options.display;
  this.pagediv=options.pagediv;
  this.Plugins=options.format;
  pageno=GetCookie('pageno')?GetCookie('pageno'):1;
  this.Open(pageno);
 },
 Result:function(http) {
  if(http.readyState == 4 ) {
        if(http.status == 200) {
    var response=http.responseText;
           response=eval("("+response+")");
     if(response.result) eval(Page.Plugins)(response.result);
     pageno=parseInt(response.page.pageno);
    totalpage=parseInt(response.page.totalpage);
     number=parseInt(response.page.number);
    try{
     eval('Page.'+Page.display)(pageno,totalpage,number);//调用分页控制函数,其实有着三个参数可以定制出更多的分页样式
    }
       catch(e){
     try{
      eval(Page.display)(pageno,totalpage,number);
     }
     catch(e){
      alert('未定义的分页控制处理函数'+Page.display);
     }
    }
   }
  }
 },
 number:function(pageno,totalpage,number) {
   pagenums=10;
   page=Math.ceil(pageno/pagenums);
   pagenum=Math.ceil(totalpage/pagenums);
   if(page==pagenum) nums=(totalpage-(pagenum-1)*pagenums); else nums=pagenums;
    htmlstr=''; 
   if(number==0) htmlstr+='当前页没有任何记录!';
   else{
    if(page==1) htmlstr+=Page.lastten;
    else
     htmlstr+=''+Page.lastten+'';
    if(pageno==1) htmlstr+=Page.lastpage;
    else
     htmlstr+=''+Page.lastpage+'';
    for(p=1;p         htmlstr+='';
         if(pageno==((page-1)*pagenums+p))
       htmlstr+='['+((page-1)*pagenums+p)+']
';
         else
       htmlstr+='['+((page-1)*pagenums+p)+']';
     }
    if(pageno==totalpage)
       htmlstr+=Page.nextpage;
    else
       htmlstr+=''+Page.nextpage+'';
    if(page==pagenum)
       htmlstr+=Page.nextten;
    else
       htmlstr+=''+Page.nextten+'';
       htmlstr+='[共'+totalpage+'页|'+number+'条记录]';
  }
     $(Ajaxdiv).innerHTML=htmlstr;
 },
 string:function(pageno,totalpage,number) {
  htmlstr='';
   if(number==0) htmlstr+='当前页没有任何记录!';
      else{
      if(pageno==1) htmlstr+=' '+Page.index+' '+Page.lastpage;
         else{
       htmlstr+=' '+Page.index+' '+Page.lastpage+'';
    }
      if(pageno==totalpage) htmlstr+=' '+Page.nextpage+' '+Page.endpage+' ';
       else{
       htmlstr+=' '+Page.nextpage+' '+Page.endpage+' ';
    }
    htmlstr+='[共'+totalpage+'页|'+number+'条记录]';
  }
     $(Page.pagediv).innerHTML=htmlstr;
 }
}//结束

 

这个文件主要的作用就是实现在客气有分页效果喽.

 

 


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software