if err.number<>0 then err.clear set conn=nothing response.write "数据库连接出错!" Response.End else conn.open connstr if err then err.clear set conn=nothing response.write "数据库连接出错!" Response.End end if end if
sub endConnection() conn.close set conn=nothing end sub
需要的话,我可以写代码
<option selected="selected" id="s1">A</option>
<option id="s2">B</option>
<option id="s3">C</option>
</select>
<input ID="text1" name="textfield" type="text" style="font-size:14" size="5" maxlength="5" />
<iframe id="myif" width="0" height="0" style="visibility:hidden" ></iframe>
<script language="javascript">
function Send_s(){
if (s1.selected==true){
document.getElementById('myif').src = "iframe.asp?s=" + s1.innerText + "&" +new Date();
}
if (s2.selected==true){
document.getElementById('myif').src = "iframe.asp?s=" + s2.innerText + "&" +new Date();
}
if (s3.selected==true){
document.getElementById('myif').src = "iframe.asp?s=" + s3.innerText + "&" +new Date();
}
}
function Get_s(s){
document.all.text1.value=s;
}</script>-=iframe.asp=-
<%
t=request("s")
arr= array("A1","B1","C1")
if t="A" then s=arr(0)
if t="B" then s=arr(1)
if t="C" then s=arr(2)
%>
<script>
var s="<%= s %>";
window.parent.Get_s(s);
</script>
修改iframe.asp为
-=iframe.asp=-
<!--#include file="conn.asp"-->
<%
t=request("s")'获取参数s,数据库表名为ABC
sql="select * from ABC where B='"&t&"'"
set rs=conn.execute(sql)
s=rs("C")
%>
<script>
var s="<%= s %>";
window.parent.Get_s(s);
</script>
-=conn.asp=-
<%dim connstr
dim conn
'下边是数据库路径
dbname="data.mdb"
connstr = "DBQ=" + server.mappath(dbname) + ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
if err.number<>0 then
err.clear
set conn=nothing
response.write "数据库连接出错!"
Response.End
else
conn.open connstr
if err then
err.clear
set conn=nothing
response.write "数据库连接出错!"
Response.End
end if
end if
sub endConnection()
conn.close
set conn=nothing
end sub
%>
他就上靠刷新隐藏的iframe中的iframe.asp页面开获取服务器信息,从而实现test.asp的免刷新,所以不能去掉iframe.asp和iframe框架,不过我建议你学习一下ajax,这个老技术实现的比较新的技术,现在比较流行,而且很方便.
<option value="" re=""></option>
<option value="1" re="A1">A</option>
<option value="2" re="B1">B</option>
<option value="3" re="C1">C</option>
<option value="4" re="D1">D</option>
<option value="5" re="E1">E</option>
</select>
<option value="" re=""></option>
<option value="1" re="A1">A</option>
<option value="2" re="B1">B</option>
<option value="3" re="C1">C</option>
<option value="4" re="D1">D</option>
<option value="5" re="E1">E</option>
</select>
<input name=reInput value="" readonly>