点击这里给我发消息 点击这里给我发消息

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

添加时间:2010-1-5
    相关阅读: ASP 页面 数据库 HTML 制作

源代码:<%@ LANGUAGE="vbscript" %>
<%
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>
<SCRIPT language=javascript>
<!--
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);
}
}
}
-->
</SCRIPT>
</HEAD>
<BODY>
<FORM action="" method="post" id="form1" name="form1">
<SELECT name="SelState" id="SelState" onchange="ChooseCity()">
<%For i = LBound(arrPr,2) To UBound(arrPr,2)%>
<OPTION value="<%=arrPr(0,i)%>"><%=arrPr(0,i)%></OPTION>
<%Next%>
</SELECT>
<SELECT name="SelCity" id="SelCity">
</SELECT>
</FORM>
</BODY>
</HTML>
第二个页面,用来生成XML文件
<%@ LANGUAGE="VBSCRIPT" %>
<%
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>
使用时注意修改数据库相关信息

本文作者:
咨询热线:020-85648757 85648755 85648616 0755-27912581 客服:020-85648756 0755-27912581 业务传真:020-32579052
广州市网景网络科技有限公司 Copyright◎2003-2008 Veelink.com. All Rights Reserved.
广州商务地址:广东省广州市黄埔大道中203号(海景园区)海景花园C栋501室
= 深圳商务地址:深圳市宝源路华丰宝源大厦606
研发中心:广东广州市天河软件园海景园区 粤ICP备05103322号 工商注册