Ajax已经听说了很长时间了,一致没有使用,感觉应该是不错的。今天作了一个简单的测试,嘿嘿,还不错!
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); //第三个参数boolean asynch表示异步否
xmlHttp.send(null);
}
function HandleStateChanged(){
var msg;
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
msg=xmlHttp.responseText;
}
else{
msg="发生错误:<br/>错误状态 " + xmlHttp.status;
}
}else{
switch(xmlHttp.readystate)
{
case 0:
//对象已建立,但是尚未初始化(尚未调用open方法)
msg="初始化对象...";
break;
case 1:
//对象已建立,尚未调用send方法
msg="正在尝试服务器连接...";
break;
case 2:
//send方法已调用,但是当前的状态及http头未知
msg="服务器连接成功。";
break;
case 3:
//已接收部分数据
//因为响应及http头不全,
//这时通过responseBody和responseText获取部分数据会出现错误,
msg="";
break;
default:
msg="未知状态!";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 %>新闻添加/修改</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("请不要从外部提交数据"):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.Error=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 %>新闻管理</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'>文章成功放入回收站!</font>")
End If %>
</div></td>
</tr>
<tr bordercolor="#FFFFFF" bgcolor="#F5F5F5">
<td width="53"><div align="center">编号</div></td>
<td width="73"><div align="center">是否删除</div></td>
<td width="729" bordercolor="#FFFFFF"><div align="center">标题</div></td>
<td width="39" bordercolor="#FFFFFF">修改</td>
<td width="37" bordercolor="#FFFFFF">确认</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("没有新闻,请上传!") %> </td>
</tr><%
Else
rem 分页设置
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>非法数据!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">修改</a></td>
<td align="left" bordercolor="#FFFFFF"><input name="OK" type="submit" class="input1" id="OK" value="确定" onClick="Javascript:alert('您确定将该条新闻放入回收站!');"></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"> </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 © 2005 BY:<%= SiteName %> . All Rights Reserved. Designer:孤剑 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 创建一个数组存储连接地址
rem 0:首页地址
rem 1:上一页的地址
rem 2:下一页的地址
rem 3:尾页的地址
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="首页" class="divPage">首页</a>
<a href="<%=url(1)%>" title="上一页" class="divPage">上一页</a>
<a href="<%=url(2)%>" title="下一页" class="divPage">下一页</a>
<a href="<%=url(3)%>" title="尾页" class="divPage">尾页</a>
每页<%=objrsPageSize%>条 / 总共 <%=objrsRecordCount%> 条
当前页: <%=objrsCurrentPage%> 总页数: <%=objrsPageCount%>
</div>
<%end sub%>