Ajax preliminary test

Source: Internet
Author: User

I have heard about Ajax for a long time and it seems to be good if it is not used. Today I made a simple test. Hey hey, it's not bad!

 

Ajax. js

// JavaScript document

VaR XMLHTTP;
VaR tagsid = "body ";
 
Function createxmlhttp (){
If (window. activexobject ){
XMLHTTP = new activexobject ("Microsoft. XMLHTTP ");
}
Else if (window. XMLHttpRequest ){
XMLHTTP = new XMLHttpRequest ();
}
}
 
Function gettextxmldata (URL ){
Createxmlhttp ();
XMLHTTP. onreadystatechange = handlestatechanged;
XMLHTTP. Open ("get", URL, false); // The third parameter Boolean asynch indicates asynchronous No
XMLHTTP. Send (null );
}
 
Function handlestatechanged (){
VaR MSG;
If (XMLHTTP. readystate = 4 ){
If (XMLHTTP. Status = 200 ){
MSG = XMLHTTP. responsetext;
}
Else {
MSG = "error: <br/> error status" + XMLHTTP. status;
}
} Else {
Switch (XMLHTTP. readystate)
{
Case 0:
// The object has been created but has not been initialized (the open method has not been called)
MSG = "initialize object ...";
Break;
Case 1:
// The object has been created and the send method has not been called
MSG = "trying to connect to the server ...";
Break;
Case 2:
// The send method has been called, but the current status and HTTP header are unknown.
MSG = "the server is successfully connected. ";
Break;
Case 3:
// Some received data
// Because the response and HTTP header are incomplete,
// If you use responsebody and responsetext to obtain some data, an error occurs,
MSG = "";
Break;
Default:
MSG = "unknown status! "; Break;
}
}
Document. getelementbyid (tagsid). innerhtml = MSG;
}

Admin_edit.asp

<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<Head>
<Title> <% = sitename %> Add/modify news </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Link href = "style/mainstyle.css" _ fcksavedurl = "" style/mainstyle.css "" _ fcksavedurl = "" style/mainstyle.css "" rel = "stylesheet" type = "text/CSS "">
<Style type = "text/CSS">
<! --
Body {
Background-color: #799ae1;
Font-size: 12px;
}
. Style1 {
Font-color: #799ae1;
Font-weight: bold;
Font-size: 18px;
}
. Style2 {color: # ff0000}
. Style4 {color: # ff0000; font-weight: bold ;}
. Style5 {color: # ffffff}
. Tableborder {
Border-Right: #183789 1px solid; border-top: #183789 1px solid; border-left: #183789 1px solid; width: 98%; border-bottom: #183789 1px solid; background-color: # ffffff
}
. Input1 {
Font-family: "";
Font-size: 12px;
Text-Decoration: none;
Height: 18px;
Width: 35px;
Border: thin inset;
}

-->
</Style>
<SCRIPT type = "text/JavaScript" src = "script/ajax. js"> </SCRIPT>
<SCRIPT type = "text/JavaScript" Language = "javascript1.1">
Tagsid = "MSG ";
</SCRIPT>
<%
Dim page
Page = trim (request. querystring ("page "))
If page = "" then
Page = 1
End if
%>
</Head>

<Body onload = "gettextxmldata ('ajax _ admin_editnews.asp? Parent = admin_managenews.asp & page = <% = Page %> ') ">
<! -- # Include file = "admin_topheader.asp" -->
<Div id = "MSG" align = "center"> </div>
</Body>
</Html>

Ajax_admin_editnews.asp

<! -- # Include file = "common/webconfig. asp" -->
<! -- # Include file = "common/clsmain. asp" -->

<%
If SESSION ("user") = "" then
Session. Abandon ()
Response. Clear ()
Response. Redirect ("admin_login.asp ")
Response. End ()
Else
Dim dsj
Set dsj = new clsdsj
If not dsj. debug then on error resume next
Dsj. clientconnected
'If not dsj. chkpost then dsj. Alert ("Please do not submit data from outside"): Response. Flush (): Response. End ()

Call listnews ()

Set dsj = nothing
End if
%>

<% Sub listnews () %>
<%
Dim newsid
Newsid = trim (request. Form ("frmnewsid "))

Dsj. chkinvstr (newsid)
If dsj. Errors = 1982 then
Response. Clear ()
Response. Write ("hacker is not good. <br> alonesword .")
End if

Dsj. connectiondatabase dsj. Database, dsj. dbuserid, dsj. dbpassword, dsj. dbtype
Dim strsql, objrs
Set objrs = server. Createobject ("ADODB. recordset ")
%>
<Form name = "form1" method = "Post" Action = "">
<Table width = "98%" border = "0" align = "center" cellpadding = "3" cellspacing = "1" class = "tableborder">
<Tr bordercolor = "#5e78d5">
<TD colspan = "5" bordercolor = "#5e78d5" bgcolor = "#5e78d5"> <Div align = "center" class = "style1 style5"> <% = sitename %> news management </div> </TD>
</Tr>
<Tr bordercolor = "# ffffff" bgcolor = "# f5f5f5">
<TD colspan = "5"> <Div align = "center">
<%
If newsid <> "then
Strsql = "Update dsj_news set deldate = '" & now () & "', whodel = '" & SESSION ("user") & "', isdeleted = true, IP = '"& dsj. getip & "'where newsid =" & newsid
Objrs. Open strsql, dsj. objconn, 1, 3
Response. Write ("<font color = Red style = 'font-size: 12px '> the article is successfully placed in the recycle bin! </Font> ")
End if %>
</Div> </TD>
</Tr>
<Tr bordercolor = "# ffffff" bgcolor = "# f5f5f5">
<TD width = "53"> <Div align = "center"> NO. </div> </TD>
<TD width = "73"> <Div align = "center"> Delete </div> </TD>
<TD width = "729" bordercolor = "# ffffff"> <Div align = "center"> title </div> </TD>
<TD width = "39" bordercolor = "# ffffff"> modify </TD>
<TD width = "37" bordercolor = "# ffffff"> OK </TD>
</Tr>
<%
Strsql = "select title, newsid, classid from dsj_news"
Strsql = strsql & "where isdeleted = false and userpower> =" & SESSION ("flag ")&""
Strsql = strsql & "order by newsid DESC"
'Objrs. Open strsql, dsj. objconn, 1, 3
Set objrs = dsj. dataprocess (strsql)
 
If objrs. EOF and objrs. bof then %>
<Tr align = "center" valign = "Middle" bordercolor = "# ffffff" bgcolor = "# f5f5f5">
<TD colspan = "5"> <% response. Write ("no news, please upload! ") %> & Nbsp; </TD>
</Tr> <%
Else
Rem paging settings
Dim rspagecount, currentpage, I
I = 1
Objrs. pagesize = 10
Rspagecount = objrs. pagecount
Currentpage = trim (request. querystring ("page "))

If dsj. chkinvstr (currentpage) then
Response. Write ("<li> invalid data! Hacker is not good! </LI> ")
Response. Write ("weburl: <br/> ")
Response. Write ("http://blog.csdn.net/alonesword ")
Response. End ()
End if

If isnumeric (currentpage) then
Currentpage = CINT (currentpage)
If currentpage <1 then
Currentpage = 1
End if
If currentpage> rspagecount then
Currentpage = rspagecount
End if
Else
Currentpage = 1
End if

Objrs. absolutepage = currentpage
 
Do While (not objrs. EOF) And I <= objrs. pagesize %>
<Tr align = "center" valign = "Middle" bordercolor = "# ffffff" bgcolor = "# f5f5f5">
<TD> <% = I %> </TD>
<TD> <input name = "frmnewsid" type = "radio" value = "<% = objrs (" newsid ") %>"> </TD>
<TD align = "Left" bordercolor = "# ffffff"> <a href = "viewnews. asp? Action = view & id = <% = objrs ("newsid") %> "target =" _ blank "Title =" <% = objrs ("title ") %> "> <% = dsj. gottopic (objrs ("title"), 95) %> </a> </TD>
<TD align = "Left" bordercolor = "# ffffff"> <a href = "admin_editnews.asp? Newsid = <% = objrs ("newsid") %> & classid = <% = objrs ("classid ") %> "target =" _ Self "> modify </a> </TD>
<TD align = "Left" bordercolor = "# ffffff"> <input name = "OK" type = "Submit" class = "input1" id = "OK" value = "OK "onclick =" javascript: alert ('Are you sure you want to put the news in the recycle bin! '); "> </TD>
</Tr>
<% I = I + 1
Objrs. movenext
Loop
End if %>
<Tr bordercolor = "# ffffff" bgcolor = "# f5f5f5">
<TD colspan = "5"> <% call divpage (currentpage, objrs. pagecount, objrs. pagesize, objrs. recordcount) %> </TD>
</Tr>
<%
Objrs. Close
Set objrs = nothing %>

<Tr align = "center" valign = "Middle" bordercolor = "# ffffff" bgcolor = "# f5f5f5">
<TD colspan = "5"> & nbsp; </TD>
</Tr>
<Tr bordercolor = "# ffffff" bgcolor = "# f5f5f5">
<TD colspan = "5"> <Div align = "center">
</Div> </TD>
</Tr>
<Tr align = "center" valign = "Middle" bordercolor = "# ffffff" bgcolor = "#5e78d5">
<TD colspan = "5"> <SPAN class = "style5"> copyright & copy; 2005 by: <% = sitename %> & nbsp ;. & nbsp; All Rights Reserved. & nbsp; designer: lone sword & nbsp; version: <% = dsj. version %> </span> </TD>
</Tr>
</Table>
</Form>
<% End sub %>

<% Sub divpage (objrscurrentpage, objrspagecount, objrspagesize, objrsrecordcount) %>
<Style>
# Dvpage {
Border-top: 1px dashed #000000;
}
</Style>
<Div align = "center" id = "dvpage">
<%
Rem creates an array storage connection address
Rem 0: Home Page address
Rem 1: Address of the previous page
Rem 2: Next page address
Rem 3: Address of the last page
Dim URL
Url = array ("#","#","#","#")

If objrscurrentpage> 1 then
URL (0) = "? Page = 1"
URL (1) = "? Page = "& objrsCurrentPage-1
End if
If objrscurrentpage <objrspagecount then
URL (2) = "? Page = "& objrscurrentpage + 1
URL (3) = "? Page = "& objrspagecount
End if
%>
<A href = "<% = URL (0) %>" Title = "Homepage" class = "divpage"> homepage </a> & nbsp; & nbsp;
<A href = "<% = URL (1) %>" Title = "Previous Page" class = "divpage"> previous page </a> & nbsp; & nbsp;
<A href = "<% = URL (2) %>" Title = "next page" class = "divpage"> next page </a> & nbsp; & nbsp;
<A href = "<% = URL (3) %>" Title = "last page" class = "divpage"> last page </a> & nbsp; & nbsp;
<% = Objrspagesize %> entries per page/total <% = objrsrecordcount %> Entries & nbsp;
Current page: <% = objrscurrentpage %> & nbsp; total page number: <% = objrspagecount %>
</Div>
<% End sub %>

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.