gpt4 book ai didi

ajax - 经典 ASP 和 Ajax 中的依赖组合?

转载 作者:行者123 更新时间:2023-12-04 07:02:30 25 4
gpt4 key购买 nike

请你能给我推荐一个经典的asp和ajax例子来制作依赖组合吗?

最佳答案

早在 AJAX 的概念正式化之前,我就使用了一种名为 XML Data Islands 的技术。来实现这种功能。显然,有许多 AJAX 框架和脚本可以实现类似的结果,但这只是我多年来在遗留应用程序中使用的久经考验的技术。

没办法快速找到合适的文章,所以挖了一些我的旧代码。基本上,当您设置父控件的值时,您会运行一些将请求发送到单独 ASP 页面的 javascript。此页面查询 DB 以确定将用于填充子控件的数据。

第二个页面以 XML 形式返回结果,该结果在主页面的 XML 数据岛中存储和操作。然后调用 javascript 解析返回的 XML 并填充子控件。

首先,我们有来自主控件的 javascript 调用:

<tr>
<td>Customer:</td>
<td>
<select id="CustomerID" NAME="CustomerID"
onfocus="javascript:populateCombo(fProcess.CustomerID.value)"
onChange="javascript:populateCombo(fProcess.CustomerID.value)"
onkeypress="javascript:populateCombo(fProcess.CustomerID.value);">
</select>
</td>
</tr>
<tr>
<td>Depot:</td>
<td>
<select name="depot" id="depot" size="1" alt="Depot">
<option value="" selected >&lt;Select Depot&gt;</option>
</select>
</td>
</tr>

然后我们有 javascript 调用第二页(从数据库中检索数据):
// Fill combo with XML data
function populateCombo(par) {
var currNode;

XMLID.async = false;

// Change Data Island source
strQuery = "Select LocationID, LocationName from Locations where CustomerID='" + par + "' and Active = 1 Order By LocationName";
XMLID.SRC="/fxdb/common/xmlQuery.asp?strQuery=" + strQuery;

// Get all "names" from XML data
objNodeList = XMLID.getElementsByTagName("LocationName");
objNodeListID= XMLID.getElementsByTagName("LocationID");


// Fill combo with names
for (var i=0; i < objNodeList.length; i++) {
fProcess.depot.options[i]=new Option(objNodeList.item(i).text,objNodeListID.item(i).text);
}

// Delete extra entries
while ( objNodeList.length < fProcess.depot.options.length) {
fProcess.depot.options[(fProcess.depot.options.length - 1)] = null;
}

}

最后,查询数据库本身的页面。
<%@ Language="VBScript" %>
<%
' Declare all variables.
Option Explicit
Dim strSql,objRS,objField
Dim sConn, oConn
Dim strName, strValue


' Buffer and output as XML.
Response.Buffer = True
Response.ContentType = "text/xml"

' Start our XML document.
Response.Write "<?xml version=""1.0""?>" & vbCrLf

' Set SQL and database connection string.

set oConn=server.createobject("adodb.connection")
sConn=Application("Connection")
oConn.Open sConn
strSQL = Request.QueryString("strQuery")

set objRS=oConn.execute(strSQL)

' Output start of data.
Response.Write "<database>" & vbCrLf

' Loop through the data records.
While Not objRS.EOF
' Output start of record.
Response.Write "<record>" & vbCrLf
' Loop through the fields in each record.
For Each objField in objRS.Fields
strName = objField.Name
strValue = objField.Value
If Len(strName) > 0 Then strName = Server.HTMLEncode(strName)
If Len(strValue) > 0 Then strValue = Server.HTMLEncode(strValue)
Response.Write "<" & strName & ">" & vbCrLf
Response.Write strValue & vbCrLf
Response.Write "</" & strName & ">" & vbCrLf
Next
' Move to next city in database.
Response.Write "</record>" & vbCrLf
objRS.MoveNext
Wend

' Output end of data.
Response.Write "</database>" & vbCrLf
%>

编辑:哎呀!我忘记了最重要的 XML Data Island 本身 - 在您的 Body 标记之后添加它。
<!-- Data Island-->
<XML ID="XMLID"></XML>

关于ajax - 经典 ASP 和 Ajax 中的依赖组合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1629569/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com