001.
<html>
002.
<head>
003.
<title>ThaiCreate.Com Ajax Tutorial</title>
004.
</head>
005.
<script language=
"JavaScript"
>
006.
var HttPRequest = false;
007.
008.
function doCallAjax(Mode,ID) {
009.
HttPRequest = false;
010.
if (window.XMLHttpRequest) { // Mozilla, Safari,...
011.
HttPRequest = new XMLHttpRequest();
012.
if (HttPRequest.overrideMimeType) {
013.
HttPRequest.overrideMimeType(
014.
}
015.
} else if (window.ActiveXObject) { // IE
016.
try {
017.
HttPRequest = new ActiveXObject(
"Msxml2.XMLHTTP"
);
018.
} catch (e) {
019.
try {
020.
HttPRequest = new ActiveXObject(
"Microsoft.XMLHTTP"
);
021.
} catch (e) {}
022.
}
023.
}
024.
025.
if (!HttPRequest) {
026.
alert(
027.
return false;
028.
}
029.
030.
var url =
031.
var pmeters =
"tMode="
+ Mode +
032.
"&tID="
+ ID;
033.
034.
HttPRequest.open(
035.
036.
HttPRequest.setRequestHeader(
"Content-type"
,
"application/x-www-form-urlencoded"
);
037.
HttPRequest.setRequestHeader(
"Content-length"
, pmeters.length);
038.
HttPRequest.send(pmeters);
039.
040.
041.
HttPRequest.onreadystatechange = function()
042.
{
043.
044.
if(HttPRequest.readyState == 3) // Loading Request
045.
{
046.
document.getElementById(
"mySpan"
).innerHTML =
"Now is Loading..."
;
047.
}
048.
049.
if(HttPRequest.readyState == 4) //
Return
Request
050.
{
051.
document.getElementById(
"mySpan"
).innerHTML = HttPRequest.responseText;
052.
}
053.
054.
}
055.
056.
}
057.
</script>
058.
<body Onload=
"JavaScript:doCallAjax('LIST','');"
>
059.
<h1>My Customer</h1>
060.
<form name=
"frmMain"
>
061.
<span id=
"mySpan"
></span>
062.
</form>
063.
</body>
064.
</html>
065.
Dim
strMode,strID
066.
067.
strMode = Request.Form(
"tMode"
)
068.
strID = Request.Form(
"tID"
)
069.
070.
Dim
Conn,strSQL,objExec,objRec
071.
Set
Conn = Server.Createobject(
"ADODB.Connection"
)
072.
Conn.Open
"DRIVER=Microsoft Access Driver (*.mdb);DBQ="
& Server.MapPath(
"db/mydatabase.mdb"
),
""
,
""
073.
074.
If
strMode =
"DELETE"
Then
075.
strSQL =
""
076.
strSQL = strSQL&
"DELETE FROM customer "
077.
strSQL = strSQL&
"WHERE CustomerID = '"
&strID&
"' "
078.
Set
objExec = Conn.Execute(strSQL)
079.
End
IF
080.
081.
082.
strSQL =
"SELECT * FROM customer ORDER BY CustomerID ASC "
083.
Set
objRec = Server.CreateObject(
"ADODB.Recordset"
)
084.
objRec.Open strSQL, Conn, 1,3
085.
%>
086.
<table width=
"600"
border=
"1"
>
087.
<tr>
088.
<th width=
"91"
> <div align=
"center"
>CustomerID</div></th>
089.
<th width=
"98"
> <div align=
"center"
>Name</div></th>
090.
<th width=
"198"
> <div align=
"center"
>Email</div></th>
091.
<th width=
"97"
> <div align=
"center"
>CountryCode</div></th>
092.
<th width=
"59"
> <div align=
"center"
>Budget</div></th>
093.
<th width=
"71"
> <div align=
"center"
>Used</div></th>
094.
<th width=
"40"
> <div align=
"center"
>Delete</div></th>
095.
</tr>
096.
<%
097.
While
Not
objRec.EOF
098.
%>
099.
<tr>
100.
<td><div align=
"center"
><%=objRec.Fields(
"CustomerID"
).Value%></div></td>
101.
<td><%=objRec.Fields(
"Name"
).Value%></td>
102.
<td><%=objRec.Fields(
"Email"
).Value%></td>
103.
<td><div align=
"center"
><%=objRec.Fields(
"CountryCode"
).Value%></div></td>
104.
<td align=
"right"
><%=objRec.Fields(
"Budget"
).Value%></td>
105.
<td align=
"right"
><%=objRec.Fields(
"Used"
).Value%></td>
106.
<td align=
"center"
><a href=
"JavaScript:doCallAjax('DELETE',' <%=objRec.Fields("
CustomerID
").Value%>');"
>Del</a></td>
107.
</tr>
108.
<%
109.
objRec.MoveNext
110.
Wend
111.
%>
112.
</table>
113.
<%
114.
objRec.Close()
115.
Conn.Close()
116.
Set
objRec =
Nothing
117.
Set
Conn =
Nothing
118.
%>