asp结合javascript,xml,sqlserver制作的无刷新二级select — IT技术

2013 年 10 月 23 日4530

源代码:<%@ LANGUAGE="vbs cript" %>
<%
strPathInfo = Request.ServerVariables("PATH_INFO")
strPathInfo = "http://" & Request.ServerVariables("SERVER_NAME") & Left(strPathInfo,InstrRev(strPathInfo,"/"))

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Provider = "sqloledb"
Conn.Open "Data Source=192.168.1.114;Initial Catalog=pubs;", "sa", "hans"
Set RS = Conn.Execute("SELECT DISTINCT sheng FROM test")
arrPr = RS.GetRows()
RS.Close
Set RS = Nothing
Conn.Close
Set Conn = Nothing
%>
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=gb_2312-80">
<TITLE></TITLE>
<s cript language=javas cript>
<!--
function ChooseCity()
{
//Clear City List
for(var i=form1.SelCity.options.length-1;i>=0;--i)
{
form1.SelCity.options.remove(i)
}
var sState = form1.SelState.options(form1.SelState.selectedIndex).value;
var oXMLDoc = new ActiveXObject('MSXML');
sURL = '<%=strPathInfo%>XMLCity.asp?State=' + sState;
oXMLDoc.url = sURL;
var oRoot=oXMLDoc.root;
if(oRoot.children != null)
{
for(var i=0;i<oRoot.children.length;++i)
{
oItem = oRoot.children.item(i);
sName = oItem.text;
var oOption = document.createElement('OPTION');
oOption.text = sName;
oOption.value = sName;
form1.SelCity.options.add(oOption);
}
}
}
-->
</s cript>
</HEAD>
<BODY>
<FORM action="" method="post">
<SELECT onchange="ChooseCity()">
<%For i = LBound(arrPr,2) To UBound(arrPr,2)%>
<OPTION value="<%=arrPr(0,i)%>"><%=arrPr(0,i)%></OPTION>
<%Next%>
</SELECT>
<SELECT>
</SELECT>
</FORM>
</BODY>
</HTML>
第二个页面,用来生成xml文件
<%@ LANGUAGE="VBs cript" %>
<%
sState = Request.QueryString("State")
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Provider = "sqloledb"
Conn.Open "Data Source=192.168.1.114;Initial Catalog=pubs;", "sa", "hans"
Set RS = Conn.Execute("SELECT city FROM test WHERE sheng='" & sState & "'")
arrCity = Rs.GetRows()
%>

<?xml version="1.0" encoding="gb2312"?>
<citys>
<%For i = LBound(arrCity,2) To UBound(arrCity,2)%>
<city><%=arrCity(0,i)%></city>
<%Next%>
</citys>
使用时注意修改数据库相关信息

字体[ 进入论坛] [ 推荐给朋友]

0 0