利用ASP和XML实现客户端多表单域数据动态更新
来源:互联网 发布:清歌五笔mac版 编辑:程序博客网 时间:2024/05/21 09:59
在基于Internet的学校学籍管理系统开发过程中,遇到这么个问题:如何实现客户端多个表单域之间的数据动态更新?如下图所示,在同一个客户端页面有三个下拉列表表单域ListCollege、ListDepart、ListClass,分别从SQLServer数据库服务器端获得学校名称、系部名称、班级名称,其中前两项数据量较小,而班级名称这一项有上百个记录。 文件1:index.asp(主页面)<!-- index.asp --><%@ LANGUAGE="VBSCRIPT"%><!--#include file="adovbs.inc" --><%strPathInfo=Request.ServerVariables("PATH_INFO")strPathInfo="http://"&Request.ServerVariables("SERVER_NAME")& left(strPathInfo,InstrRev(strPathInfo,"/"))set conn=Server.CreateObject("ADODB.connection")conn.open"driver={SQL Server};server=JYZD-WMG;uid=sa;pwd=;database=gzz_back;"%><%set Rscollege= Server.CreateObject("ADODB.Recordset")Rscollege.Source ="SELECT DISTINCT college_name FROM dbo.pcollege"Rscollege.activeconnection=connRscollege.CursorType = 0Rscollege.CursorLocation = 2Rscollege.LockType = 3Rscollege.Open()arrcollege=rscollege.GetRows()Rscollege.numRows = 0%><%set Recordset3 = Server.CreateObject("ADODB.Recordset")Rsdepartment.Source ="SELECT department_name FROM dbo.pdepartment"Rsdepartment.activeconnection=connRsdepartment.CursorType = 0Rsdepartment.CursorLocation = 2Rsdepartment.LockType = 3Rsdepartment.Open()arrdepartment=Rsdepartment.GetRows()Rsdepartment.numRows = 0%><%Rscollege.Close()Rsdepartment.Close()conn.close()set Rscollege=nothingset Rsdepartment=nothing%><script language="vbscript"><!--sub beginyear_onclick()classfrm.endyear.value=classfrm.beginyear.value+1end sub--></script><html><head><title>用ASP和XML实现多表单域数据动态更新示例</title><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><script language="javascript"><!--function SelectClass(){//清空班级表单for(var i=classfrm.listclass.options.length-1;i>=0;--i){classfrm.Listclass.options.remove(i);}var collegename=classfrm.listschool.options(classfrm.listschool.selectedIndex).value;var departname=classfrm.listdepart.options(classfrm.listdepart.selectedIndex).value;var oXMLDoc=new ActiveXObject('MSXML');sURL='<%=strPathInfo%>XMLclass.asp?college='+collegename+'&depart='+departname; 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;classfrm.listclass.options.add(oOption);}}}--></script></head><body text="#000000" bgcolor="#FFFFD7"><div align="center"> <table width="80%" border="1" bordercolordark=darkgray bordercolorlight=aliceblue height="210" align="center" ><tr> <td colspan="2" height="4"> <div align="center"> <font size="5"><b>综合示例</b></font></div></td></tr><tr> <td width="145" height="186"> <div align="center"><font color="#000000">请选择 </font></div><p align="center"><font color="#000000">学年/学期/班级</font></p></td><td width="443" height="186" > <form name="classfrm" method="post" action="SearchPlan.asp"><div align="center"> <%dim sumyear %><%sumyear=year(date)+1%><select name="classbeginyear" size="1" ><option value="<%=sumyear%>" ><%=sumyear%></option><%sumyear=sumyear-1%><option value="<%=sumyear%>" selected><%=sumyear%></option><%for i=1 to 18 %><%sumyear=sumyear-1%><option value="<%=sumyear%>" ><%=sumyear%></option><%next%></select>至 <%sumyear=year(date)%><input name="classendyear" value="<%=sumyear+1%>" readonly >年度 <select name="classterm" size="1"><option value="1" selected>第一</option><option value="2">第二</option></select>学期<br><br><select name="classschool" id="classschool" onchange="chooseclass()"><%for i=lbound(arrpr1,2) to ubound(arrpr1,2)%><option value="<%=arrpr1(0,i)%>"><%=arrpr1(0,i)%></option><%next%></select>学校 <select name="classdepart" id="classdepart" onchange="chooseclass()"><%for i=lbound(arrpr3,2) to ubound(arrpr3,2)%><option value="<%=arrpr3(0,i)%>"><%=arrpr3(0,i)%></option><%next%></select>系部<br> <br><select name="classname" id="classname"> </select><script language="vbscript"><!--call chooseclass()--></script>班级</div><p align="center"> <input type="submit" name="Submit1" value="确定发送" onClick="searchclass"><input type="reset" name="reset1" value="重填"> </p></form></td></tr></table></div> </body></html>
文件2:xmlclass.asp(动态数据查询,由主页面获得查询值)<!-- xmlclass.asp --><%@ LANGUAGE="VBSCRIPT" %><%collegename=trim(Request.QueryString("college"))departmentname=trim(Request.QueryString("depart"))set conn=Server.CreateObject("ADODB.connection")conn.open "driver={SQL Server};server=JYZD-WMG;uid=sa;pwd=;database=gzz_back;"changstr="select class_name from pclass where specialty_code in ( select specialty_code from pspecialty where college_code in ( select college_code from pcollegewhere college_name='"&collegename&"') and department_code in ( selectdepartment_code from pdepartment where department_name='"&departmentname&"')) "set Rsclass = Server.CreateObject("ADODB.Recordset")Rsclass.Source =changstrRsclass.activeconnection=connRsclass.CursorType = 0Rsclass.CursorLocation = 2Rsclass.LockType = 3Rsclass.Open()arrclass=recordset2.GetRows()Rsclass.numRows = 0%><? xml version="1.0" encoding="gb2312" ?><classes><%For i =LBound(arrclass,2) To UBound(arrclass,2)%><class><%=arrclass(0,i)%></class><%Next%></classes>
在index.asp中,当在listcollege或listdepart两个下拉列表中选择了相应的学校和系部后,触发selectclass函数,在此函数中通过ASP文件传值方式(如xmlclass?college=江阴高等技术学院&depart=电子工程系)向xmlclass.asp传递查询条件,然后由Rsclass记录集从服务器端获得符合条件的班级记录,并通过数组返送到客户端listclass下拉列表。通过这种方式,从而在不刷新页面、只传递少量数据的情况下实现了客户端多表单域的数据动态更新。
WWW服务器
windows 2000 server(IIS 5)
数据库
SQL Server 7.0
浏览器
Internet Explore 5.5
数据库名称
gzz_back
数
据
库
结
构
table名称
字段1
字段2
字段3
字段4
pcollege
college_name
college_code
pdepartment
department_name
department_code
pspecialty
specialty_name
specialty_code
college_code
department_code
pclass
specialty_code
class_name
class_code
文件2:xmlclass.asp(动态数据查询,由主页面获得查询值)<!-- xmlclass.asp --><%@ LANGUAGE="VBSCRIPT" %><%collegename=trim(Request.QueryString("college"))departmentname=trim(Request.QueryString("depart"))set conn=Server.CreateObject("ADODB.connection")conn.open "driver={SQL Server};server=JYZD-WMG;uid=sa;pwd=;database=gzz_back;"changstr="select class_name from pclass where specialty_code in ( select specialty_code from pspecialty where college_code in ( select college_code from pcollegewhere college_name='"&collegename&"') and department_code in ( selectdepartment_code from pdepartment where department_name='"&departmentname&"')) "set Rsclass = Server.CreateObject("ADODB.Recordset")Rsclass.Source =changstrRsclass.activeconnection=connRsclass.CursorType = 0Rsclass.CursorLocation = 2Rsclass.LockType = 3Rsclass.Open()arrclass=recordset2.GetRows()Rsclass.numRows = 0%><? xml version="1.0" encoding="gb2312" ?><classes><%For i =LBound(arrclass,2) To UBound(arrclass,2)%><class><%=arrclass(0,i)%></class><%Next%></classes>
在index.asp中,当在listcollege或listdepart两个下拉列表中选择了相应的学校和系部后,触发selectclass函数,在此函数中通过ASP文件传值方式(如xmlclass?college=江阴高等技术学院&depart=电子工程系)向xmlclass.asp传递查询条件,然后由Rsclass记录集从服务器端获得符合条件的班级记录,并通过数组返送到客户端listclass下拉列表。通过这种方式,从而在不刷新页面、只传递少量数据的情况下实现了客户端多表单域的数据动态更新。
- 利用ASP和XML实现客户端多表单域数据动态更新
- 利用userData实现客户端保存表单数据
- 利用userData实现客户端保存表单数据
- 利用userData实现客户端保存表单数据
- 利用userData实现客户端保存表单数据
- 利用userData实现客户端保存表单数据
- 利用ASP编写动态回复表单
- 利用VC++实现对XML结点的更新和追加
- 利用ASP发送和接收XML数据的处理方法
- 利用ASP发送和接收XML数据的处理方法
- 利用ASP发送和接收XML数据的处理方法
- 利用ASP发送和接收XML数据的处理方法
- asp取动态表单中数据并写入xml文件,用xsl显示
- 利用ASP.NET服务器端自定义控件实现XML文件中还原表单
- 利用ASP.NET服务器端自定义控件实现XML文件中还原表单
- 利用ASP.NET服务器端自定义控件实现XML文件中还原表单
- 利用php和ajax实现局部更新数据
- 利用 BeanUtils 实现多表单间冗余数据同步管理
- 累
- asp从数据库里读出复选框是否被选中
- 网站日志收集方式简介
- javascript弹出窗口详解
- 弹出自定义模式对话框
- 利用ASP和XML实现客户端多表单域数据动态更新
- showModalDialog和showModelessDialog使用心得
- ASP开发小技巧集锦
- Java 5种字符串拼接方式性能比较。
- 关于delete 和 delete[] (一)
- 关于delete 和 delete[ ] (二)
- spring
- 明天去天水 消失了
- Web行业超小型技术调查