嘿所有我想弄清楚如何更新我当前的代码,这样我就不必刷新页面了。
但是,考虑到我的asp代码是如何布局的,我不知道如何做到这一点。
我的示例代码是:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Dim Connection
Dim ConnString
Dim Recordset
Dim row1(11)
Dim row2(11)
Dim row3(11)
...
Dim row29(11)
Dim intX
Dim shift(19)
ConnString="DRIVER={SQL Server};SERVER=xxxxx;UID=xxxxx;PWD=xxxxxxx;DATABASE=rtd"
SQL = "SELECT * FROM dbo.RTDtable ORDER BY ID"
Set Connection = Server.CreateObject("ADODB.Connection")
Set Recordset = Server.CreateObject("ADODB.Recordset")
Connection.Open ConnString
Recordset.Open SQL,Connection
If Recordset.EOF Then
Response.Write("No records returned.")
Else
intX = 0
Do While NOT Recordset.Eof
row1(intX) = Recordset("Production_Date")
row2(intX) = Recordset("GroupID")
row3(intX) = Recordset("Shift")
row4(intX) = Recordset("Shift_Name")
row5(intX) = Recordset("Full_Shift")
row6(intX) = Recordset("Stn_ID")
row7(intX) = Recordset("Stn_ID2")
row8(intX) = Recordset("Point_Name")
row9(intX) = Recordset("Bucket_1")
row10(intX) = Recordset("Bucket_2")
row11(intX) = Recordset("Bucket_3")
row12(intX) = Recordset("Bucket_4")
row13(intX) = Recordset("Bucket_5")
row14(intX) = Recordset("Bucket_6")
row15(intX) = Recordset("Bucket_7")
row16(intX) = Recordset("Bucket_8")
row17(intX) = Recordset("Bucket_9")
row18(intX) = Recordset("Bucket_10")
row19(intX) = Recordset("Bucket_11")
row20(intX) = Recordset("Bucket_12")
row21(intX) = Recordset("Bucket_13")
row22(intX) = Recordset("Bucket_14")
row23(intX) = Recordset("Bucket_15")
row24(intX) = Recordset("Bucket_16")
row25(intX) = Recordset("Bucket_17")
row26(intX) = Recordset("Bucket_18")
row27(intX) = Recordset("Bucket_19")
row28(intX) = Recordset("Bucket_20")
row29(intX) = Recordset("Total")
intX = IntX + 1
Recordset.MoveNext
Loop
End If
Recordset.Close
Set Recordset=nothing
Connection.Close
Set Connection=nothing
%>
在打电话给我之后,将其插入表格中:
<tr>
<td class="tableHeading">1680-1L</td>
<td valign="bottom"><span id="ctl00_ContentPlaceHolder1_dgDetails_ctl06_lblDowntime"></span></td>
<td align="left" class="fontSizes">ACTUAL</td>
<td align="right"><% response.write row9(1) %></td>
<td align="right"><% response.write row10(1) %></td>
<td align="right"><% response.write row11(1) %></td>
<td align="right"><% response.write row12(1) %></td>
<td align="right"><% response.write row13(1) %></td>
<td align="right"><% response.write row14(1) %></td>
<td align="right"><% response.write row15(1) %></td>
<td align="right"><% response.write row16(1) %></td>
<td align="right"><% response.write row17(1) %></td>
<td align="right"><% response.write row18(1) %></td>
<td align="right"><% response.write row19(1) %></td>
<td align="right"><% response.write row20(1) %></td>
<td align="right"><% response.write row21(1) %></td>
<td align="right"><% response.write row22(1) %></td>
<td align="right"><% response.write row23(1) %></td>
<td align="right"><% response.write row24(1) %></td>
<td align="right"><% response.write row25(1) %></td>
<td align="right"><% response.write row26(1) %></td>
<td align="right"><% response.write row27(1) %></td>
<td align="right"><% response.write row28(1) %></td>
<td align="right"><% response.write row29(1) %></td>
</tr>
<tr>
<td></td>
<td valign="bottom"></td>
<td align="left" class="fontSizes">TARGET</td>
<td align="right"><% response.write row9(2) %></td>
<td align="right"><% response.write row10(2) %></td>
<td align="right"><% response.write row11(2) %></td>
<td align="right"><% response.write row12(2) %></td>
<td align="right"><% response.write row13(2) %></td>
<td align="right"><% response.write row14(2) %></td>
<td align="right"><% response.write row15(2) %></td>
<td align="right"><% response.write row16(2) %></td>
<td align="right"><% response.write row17(2) %></td>
<td align="right"><% response.write row18(2) %></td>
<td align="right"><% response.write row19(2) %></td>
<td align="right"><% response.write row20(2) %></td>
<td align="right"><% response.write row21(2) %></td>
<td align="right"><% response.write row22(2) %></td>
<td align="right"><% response.write row23(2) %></td>
<td align="right"><% response.write row24(2) %></td>
<td align="right"><% response.write row25(2) %></td>
<td align="right"><% response.write row26(2) %></td>
<td align="right"><% response.write row27(2) %></td>
<td align="right"><% response.write row28(2) %></td>
<td align="right"><% response.write row29(2) %></td>
</tr>
<tr>
etc etc
那么我如何通过AJAX进行此更新,因为我在html代码中有这个更新?
感谢您的时间,
大卫
获取示例:
$.get('resultPage.asp', function(data) {
// Extract just the HTML for the table
var ixTableStart = data.indexOf('<td', data.indexOf('id="Row9-1"'));
var ixTableEnd = data.indexOf('</td>', ixTableStart) + 8;
var resultTableHtml = data.substring(ixTableStart, ixTableEnd);
$('.Row9-1).html(resultTableHtml);
etc etc...
});
<tr>
<td class="tableHeading">1680-1L</td>
<td valign="bottom"><span id="ctl00_ContentPlaceHolder1_dgDetails_ctl06_lblDowntime"></span></td>
<td align="left" class="fontSizes">ACTUAL</td>
<td align="right" id="row9-1">51</td>
<td align="right" id="row10-1">10</td>
<td align="right" id="row11-1">16</td>
etc.....
<tr>
<td></td>
<td valign="bottom"></td>
<td align="left" class="fontSizes">TARGET</td>
<td align="right" id="row9-2">5</td>
<td align="right" id="row10-2">16</td>
etc...
答案 0 :(得分:1)
如果我正确理解您的问题,您所做的只是通过点击按钮或通过setInterval
javascript方法刷新页面,特别是表格中显示的结果。
假设您的结果<table>
位于<div>
或具有id
属性resultPanel
的类似容器元素和数字中,那么您可以使用以下内容:
$.get('resultPage.asp', function(data) {
FillResultPanel("resultPanel1");
FillResultPanel("resultPanel2");
FillResultPanel("resultPanel3");
FillResultPanel("resultPanel4");
});
function FillResultPanel(panelId) {
// Extract just the HTML for the table
var ixTableStart = data.indexOf('<table', data.indexOf('id="' + panelId + '"'));
var ixTableEnd = data.indexOf('</table>', ixTableStart) + 8;
var resultTableHtml = data.substring(ixTableStart, ixTableEnd);
$('#' + panelId).html(resultTableHtml);
}
编辑:正如您在聊天中提到的,您有4个表要更新,我更新了我的解决方案,以提供特定于该方案的示例。