Ajax+asp Source Code] table that reads the contents of the database (no frames) 1th/2 page _ajax related

Source: Internet
Author: User
Function:
A table that reads the contents of the database. Read the data in Ajax, paging too. The code is not well written. For some learning Ajax friend reference. If there is any problem, please keep the code.
There is still a small problem, if there is a friend interested in helping me to solve the next grateful
When you turn to the last page, if only one line will appear blank and undefined. I've tried a lot of ways to solve this problem.
Note: Some of the following places show smiley faces in uppercase D
In fact, many places can be based on the output of the ASP file characters control. At present, there is no improvement in that area. For example, a column shows how many rows.
Code for ASP pages:
FileName: Demo. Asp
Copy Code code as follows:

' The sub below is a deferred loading for debugging Ajax
<%
Sub Timedelayseconds (delayseconds)
Seccount = 0
SEC2 = 0
While Seccount < Delayseconds + 1
SEC1 = Second (Time ())
If Sec1 <> Sec2 Then
SEC2 = Second (Time ())
Seccount = Seccount + 1
End If
Wend
End Sub
Timedelayseconds (0)
%>

<%
Response.Expires =-9999
Response.AddHeader "Pragma", "No-cache"
Response.AddHeader "Cache-ctrol", "No-cache"
Response.Charset = "GB2312"

Set conn = Server.CreateObject ("ADODB. Connection ")
Connstr= "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Server.MapPath ("Database.mdb")
Conn. Open ConnStr
%>

<%
Set rs = Server.CreateObject ("Adodb.recordset")
SQLSTR = "SELECT * from UserData ORDER by id"
Rs.Open sqlstr,conn,1,1
Rs. PageSize = 3
Allpage = Rs. PageCount

Page = Request. QueryString ("page")

' *********************** judgment
If CInt (page) =< 1 Then
Page = 1
ElseIf CInt (page) >= Rs. PageCount Then
Page = Rs. PageCount
Else
intpage = CInt (page)
End If
'***************************

Rs. Absolutepage=page

Response.Write allpage& "," &rs. absolutepage& ","

For i = 1 to Rs. PageSize
If Rs. EOF or Rs. BOF then Exit for
Response.Write Rs (0) & "," &rs (1) & "," &rs (2) & "," &rs (3) & ","
Rs.movenext
Next

Rs.close
Set rs = Nothing
%>


Ajax-Processed page code
FileName: ajax.js
Copy Code code as follows:

var request = false;
------------------judge the browser and establish the object----------------------------------------------------------------
try {//attempt to create XMLHttpRequest object
Request = new XMLHttpRequest (); ---This object will be compatible with most browsers except IE!
}                                                                         //-
catch (Trymicrosoft) {//if failed catch (Trymicrosoft)

try {//attempt to use a newer version IE compatible object (msxml2.xmlhttp)
Request = new ActiveXObject ("Msxml2.xmlhttp"); ---This object will be compatible with older versions of IE
}                                                                          //-
catch (Othermicrosoft) {//if failed catch (Othermicrosoft)

try {//attempt to use older version of IE compatible object (microsoft.xmlhttp)
Request = new ActiveXObject ("Microsoft.XMLHTTP"); ---This object will be compatible with the new version of IE
}                                                                          //-
catch (FAILED) {//if failed catch (failed)
Request = false; Request = False
Alert ("Object error!");
}
}
}
Defaultpages ();
//------------------------------------------------------------------------------------------------------------- */


Reading data ***********************************************************

function Defaultpages () {
var url = "Demo.asp";
Request.open ("Get", url, True); Open method ("mode", URL, asynchronous)
Request.onreadystatechange = Updatepage; Determine the results of server processing
Request.send (NULL); Sent out.
}

function Selectpages (method,pages) {

Delete the previous data first
for (i=0;i<3;i++)
document.getElementById ("MyTable"). DeleteRow ();
//----------------

if (method = = "Previous") {
var pagetemp = document.getElementById ("Pagenow"). Value;
var pagenow = parseint (pagetemp)-1;

alert (pagenow);//debug

var url = "Demo.asp?" Page= "+pagenow;
Request.open ("Get", url, True);
Request.onreadystatechange = Updatepage;
Request.send (NULL);
}

else if (method = = "Next") {
var pagetemp = document.getElementById ("Pagenow"). Value;
var pagenow = parseint (pagetemp) +1;

alert (pagenow);//debug

var url = "Demo.asp?" Page= "+pagenow;
Request.open ("Get", url, True);
Request.onreadystatechange = Updatepage;
Request.send (NULL);
}
}

Whether the server is finished processing. **********************************************************************************

function Updatepage () {
if (request.readystate <= 3) {//less than or equal to state 3----loading.
document.getElementById ("Status"). InnerHTML = "Loading ...";
document.getElementById ("Pages"). InnerHTML = "Previous│next";
}

if (request.readystate = = 4) {//state 4----complete.
if (Request.status = = 200) {//If the HTTP status is 200--when the fetch data is successfully obtained.
Requestallright ();
}else{//If HTTP status is 404--http error.
document.getElementById ("Status"). InnerHTML = "Error:" + request.status;
document.getElementById ("Pages"). InnerHTML = "Previous│next";
}
}
}

Process completion-Generate data. **********************************************************************************

function Requestallright () {
var getstr = Request.responsetext;
var getValue = Getstr.split (",");
var pagecount = getvalue[0];
var pagenow = getvalue[1];

var contact = [
[Getvalue[2],getvalue[3],getvalue[4],getvalue[5]],
[Getvalue[6],getvalue[7],getvalue[8],getvalue[9]],
[Getvalue[10],getvalue[11],getvalue[12],getvalue[13]]
];

for (Var list=0; list<contact.length; list++) {
var mytr = Mytable.insertrow (); Create a TR tag
for (Var cell=0; cell<contact[list].length; cell++) {//td loop
var mytd = Mytr.insertcell (); Create TD tags
mytd.innerhtml = Contact[list][cell]; Insert content for TD tags
if (Cell = = 0)//If the current is the first TD for each line
Mytd.id = "number"; Give it an ID of number
}
}

On the next page of the judgement, whether you can click ******************************************************************************************
if (Pagenow = = PageCount) {
document.getElementById ("Pages"). InnerHTML = "<a href=javascript:selectpages (' Previous ', ' 0 '); Target=_self Class=pagestag>previous</a>│next "
}
else if (Pagenow = 1) {
document.getElementById ("Pages"). InnerHTML = "Previous│<a href=javascript:selectpages (' Next ', ' 0 '); Target=_self class=pagestag>next</a> "
}
else if (pagenow!= 1 | | Pagenow!= PageCount) {
document.getElementById ("Pages"). InnerHTML = "<a href=javascript:selectpages (' Previous ', ' 0 '); Target=_self class=pagestag>previous</a>│<a href=javascript:selectpages (' Next ', ' 0 '); Target=_self class=pagestag>next</a> "
}
On the next page of the judgement, whether you can click ******************************************************************************************

document.getElementById ("PageCount"). Value = PageCount;
document.getElementById ("Pagenow"). Value = Pagenow;
document.getElementById ("Status"). InnerHTML = "Done with!";

alert (PageCount);//debug
alert (pagenow);//debug

}

Current 1/2 page 12 Next read the full text
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.