Ajax space and paging function _ javascript Skills Used in the Business Edition

Source: Internet
Author: User
The ajax space and paging functions used in the Business Edition are the ajax space and paging functions used in the SQL Business Edition. Their js Code learning is very good.
// Ajax Control
Function PageAjax (){
Var xhrObj = null;
If (window. XMLHttpRequest)
{
XhrObj = new XMLHttpRequest ();
}
Else if (window. ActiveXObject)
{
Try {
XhrObj = new ActiveXObject ("Microsoft. XMLHTTP ");
}
Catch (e1)
{
Try {
XhrObj = new ActiveXObject ("MSXML2.XMLHTTP ");
}
Catch (e2 ){
Try {
XhrObj = new ActiveXObject ("MSXML3.XMLHTTP ");
}
Catch (e3 ){
Alert ("failed to Create Ajax:" + e3)
}
}
}
}
Else
{
Alert ("Unrecognized browsers ");
}
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 );
Xhr. onreadystatechange = function (){
If (xhr. readyState = 1)
{
If (p = 1)
Eval ('document. all. '+ c_obj). innerHTML ="

Connecting to the server...

";
}
Else if (xhr. readyState = 2 | xhr. readyState = 3)
{
If (p = 1)
Eval ('document. all. '+ c_obj). innerHTML ="

Reading data...

";
}
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 = "Total" + this. count + this. itemunit + "homepage previous page next page last page:" + this. page + "/" + this. pagecount + "page" + this. perpagenum + this. itemunit + this. itemname + "/page ";
Break;
Case 2:
Statushtml = "" + this. pagecount + "Page/" + 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) % 10) + 2 );
For (var I = startpage; I <= this. pagecount; 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 = "Total" + this. pagecount + "Page/" + this. count + this. itemunit + this. itemname + "9 7 ";
For (var I = this. page; I <= this. pagecount; I ++ ){
If (I = this. page)
Statushtml + =" "+ I +""
Else
Statushtml + = "[" + I + "]"
N = n + 1;
If (n> 10) break;
}
Statushtml + = "8 :";
Break;
Case 3:
Statushtml = "th" + this. page + "page total" + this. pagecount + "page <>" + this. perpagenum + this. itemunit + this. itemname + "/page ";
Break;
}
Statushtml + = "no. ";For (var I = 1; I <= this. pagecount; I ++ ){If (I = this. page)Statushtml + =""+ I +"";ElseStatushtml + =""+ I +"";}Statushtml + ="Page ";
GetObject (this. p_obj). innerHTML = statushtml;
}
Function homePage ()
{
If (this. page = 1)
Alert ("It's already the homepage! ")
Else
LoadData (1 );
}
Function lastPage ()
{
If (this. page = this. pagecount)
Alert ("this is 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 );
}
Related Article

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.