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%>