删除数据库条目后重新加载 html table 数据

reload html table data after database entry deleted

我正在使用 asp classic 构建网页,并将 mdb 填充到 html 中,每行末尾都有删除按钮。单击删除按钮时,数据库条目将被删除,但 html table 不会重新加载并反映数据更改。单击删除按钮时如何实现这一点?这是我的代码:

<%@ Language=VBScript %>
<% Option Explicit %>

<!--#include virtual="/adovbs.inc"-->

<HTML>
<%
        Dim objConn
        Set objConn = Server.CreateObject("ADODB.Connection")
        objConn.ConnectionString="DRIVER={Microsoft Access Driver (*.mdb)};" & "DBQ=C:\Inetpub\wwwroot\Scott1\EmployeeDB.mdb"

        objConn.Open

        Dim objRS
        Set objRS = Server.CreateObject ("ADODB.RecordSet")

        objRS.Open "Employee", objConn, , adLockOptimistic, adCmdTable

%>
<FORM METHOD=POST ACTION="default.asp">
<TABLE>

    <tr><td>First Name:</td><td><INPUT TYPE=INPUT NAME="FirstName"></td></tr>
    <tr><td>Last Name:</td><td><INPUT TYPE=INPUT NAME="LastName"></td></tr>
    <tr><td>Employee ID:</td><td><INPUT TYPE=INPUT NAME="EmployeeID"></td></tr>
    <TR><TD><INPUT TYPE=SUBMIT NAME=ADD VALUE="Add"></td></tr>
<%
    objRS.AddNew
    objRS("FirstName") = Request.Form("FirstName")
    objRS("LastName") = Request.Form("LastName")
    objRS("EmployeeID") = Request.Form("EmployeeID")
    objRS.Update
%>

</TABLE>
</FORM>


<FORM METHOD=POST ACTION="default.asp">
<TABLE BORDER=2 WIDTH=500>

    <TR BGCOLOR='#f8f8f8'>
        <TD>First Name</TD>
        <TD>Last Name</TD>
        <TD>Employee ID</TD>
        <TD>Delete</TD>
    </TR>

<%

    Do While Not objRS.EOF

        Response.Write "<TR><TD>" & objRS("FirstName") & "</TD>"
        Response.Write "<TD>" & objRS("LastName") & "</TD>"
        Response.Write "<TD>" & objRS("EmployeeID") & "</TD>"
        Response.Write "<TD><INPUT TYPE=SUBMIT NAME=Delete VALUE=Delete >" & objRS.Delete & "</TD></TR>"

        objRS.MoveNext

    Loop

    objRS.Close
    Set objRS = Nothing
    objConn.Close
    Set objConn = Nothing

%>

</table>


</FORM>
</HTML>

可能最简单的方法是根据当前记录的 id 给每个 <tr> 一个 id 然后使用 JavaScript 到 post 到删除例程(这将是保存在单独的 ASP 文件中),然后通过更改 style.display.

隐藏该行
<tr id="row<%= rs("recordId") %>>
    <td>...</td>
    <td>...</td>
    <td>
        <input type="button" value="Delete" OnClick="deleteRow(<%= rs("recordId") %>);"
    </td>
</tr>

JavaScript 可能类似于...

var xmlhttp;
if (window.XMLHttpRequest) xmlhttp=new XMLHttpRequest();    // code for IE7+, Firefox, Chrome, Opera, Safari...
else xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");      // code for IE6, IE5

function ajaxPage(postPage, paramList) {xmlhttp.open("POST",postPage,false);xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");xmlhttp.send(paramList);return xmlhttp.responseText;}

function deleteRow(id) {
    ajaxPage("deleteFunctionPage.asp", "id=" + id);
    document.getElementById("row" + id).style.display = "none";
}