Home > Web Front-end > JS Tutorial > Ajax space and paging functions used in Kexun Business Edition_javascript skills

Ajax space and paging functions used in Kexun Business Edition_javascript skills

WBOY
Release: 2016-05-16 19:09:09
Original
1165 people have browsed it

The ajax space and paging functions used in the commercial version of Kexun SQL, their js code learning is very good
//ajax control
function PageAjax(){
var xhrObj=null;
if(window.XMLHttpRequest)
                                                        Obj=newActiveXObject ("Microsoft.XMLHTTP");
}
catch(e1)
try{
xhrObj=new ActiveXObject("MSXML2. catch(e2){
try{
xhrObj=new ActiveXObject("MSXML3.XMLHTTP");
}
catch(e3){
alert("Failed to create Ajax:" e3)
}
}
}
}
else
{
alert("Unrecognized browser");
}
return xhrObj;
}

function Page(curPage,labelid,classid,installdir,url,refreshtype,specialid)
{
this.labelid=labelid;
this.classid=classid;
this.url=url;
if (labelid.substring(0,5)=="{SQL_")
{
var slabelid=labelid.split('(')[0];
slabelid=slabelid.replace("{","");
this.c_obj="c_" slabelid;
this.p_obj="p_" slabelid;
}
else
{
this.c_obj="c_" labelid;
this.p_obj="p_" labelid;
}
this.installdir=installdir;
this.refreshtype=refreshtype;
this.specialid=specialid;
this.page=curPage;
loadData(1);
}
function loadData(p)
{ this.page=p;
var xhr=new PageAjax();
xhr.open("get",installdir url "?labelid=" escape(labelid) "&classid=" classid "&refreshtype=" refreshtype "&specialid=" specialid "&curpage=" p, true);      eval('document.all. ' c_obj).innerHTML="

Connecting to server...
";
                                                                                                                                                                                                                                                                🎜>                                                                                                                             ";
              }
              else if(xhr.readyState==4)
              {
             if (xhr.status==200)
             {
                  var pagearr=xhr.responseText.split("{ks:page}")
                  var pageparamarr=pagearr[1].split("|");
                  count=pageparamarr[0];    
                  perpagenum=pageparamarr[1];
                  pagecount=pageparamarr[2];
                  itemunit=pageparamarr[3];   
                  itemname=pageparamarr[4];
                  pagestyle=pageparamarr[5];
                  getObject(c_obj).innerHTML=pagearr[0];
                  pagelist();
             }
            }
       }
    xhr.send(null); 
}
function getObject(id) 
{
    if(document.getElementById) 
    {
        return document.getElementById(id);
    }
    else if(document.all)
    {
        return document.all[id];
    }
    else if(document.layers)
    {
        return document.layers[id];
    }
}

function pagelist()
{
 var n=1;    
 var statushtml=null;
 switch(parseInt(this.pagestyle))
 {
  case 1:    
     statushtml="共" this.count this.itemunit " 首页 上一页 下一页 尾页 页次:" this.page "/" this.pagecount "页 " this.perpagenum this.itemunit this.itemname "/页";
        break;
  case 2:
     statushtml="" this.pagecount "页/" this.count this.itemunit " 9 7 ";
     var startpage=1;
     if (this.page==10)
       startpage=2;
     else if(this.page>10)
       startpage=eval((parseInt(this.page/10)-1)*10 parseInt((this.page)) 2);
      for(var i=startpage;i          if (i==this.page)
           statushtml ="" i " "
          else
            statushtml ="" i " "
            n=n 1;
          if (n>10) break;
      }
     statushtml ="8 :";
     statushtml="" statushtml "";
    break;     
  case 4:
     statushtml="共" this.pagecount "页/" this.count this.itemunit this.itemname " 9 7 ";
      for(var i=this.page;i          if (i==this.page)
           statushtml ="" i " "
          else
            statushtml ="[" i "] "
            n=n 1;
          if (n>10) break;
      }
     statushtml ="8 :";
    break;     
  case 3:
     statushtml="第" this.page "页 共" this.pagecount "页   > >> " this.perpagenum this.itemunit this.itemname "/页";
   break;
 }
statushtml =" No. page";
getObject(this.p_obj).innerHTML=statushtml;
}
function homePage()
{
if(this.page==1)
alert("It’s already the home page! ")
else
loadData(1);
}
function lastPage()
{
if(this.page==this.pagecount)
alert("already It’s the last page! ")
else
loadData(this.pagecount);
}
function previousPage()
{
if (this.page>1)
loadData(this.page-1);
else
alert("Already the first page");
}

function nextPage()
{
if(this.page loadData(this.page 1);
else
alert("The last page has been reached");
}
function turn( i)
{
loadData(i);
}

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template