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 );
}