时间:2021-05-25
1.请在sqlserver中建一数据库name:house在house中运行下列脚本
ifexists(select*fromsysobjectswhereid=object_id(N´[dbo].[City]´)andOBJECTPROPERTY(id,N´IsUserTable´)=1)
droptable[dbo].[City]
GO
ifexists(select*fromsysobjectswhereid=object_id(N´[dbo].[Area]´)andOBJECTPROPERTY(id,N´IsUserTable´)=1)
droptable[dbo].[Area]
GO
CREATETABLE[dbo].[City](
[id][int]IDENTITY(1,1)NOTNULL,
[name][nvarchar](10)NULL
)ON[PRIMARY]
GO
CREATETABLE[dbo].[Area](
[id][int]IDENTITY(1,1)NOTNULL,
[CityId][int]NULL,
[name][nvarchar](20)NULL
)ON[PRIMARY]
GO
INSERTINTOCity(id,name)Values(1,"广州")
INSERTINTOCity(id,name)Values(2,"上海")
INSERTINTOCity(id,name)Values(3,"北京")
INSERTINTOArea(id,CityId,name)Values(1,1,"天河")
INSERTINTOArea(id,CityId,name)Values(2,1,"白云")
INSERTINTOArea(id,CityId,name)Values(3,2,"虹口")
INSERTINTOArea(id,CityId,name)Values(4,2,"宝山")
INSERTINTOArea(id,CityId,name)Values(5,2,"静安")
INSERTINTOArea(id,CityId,name)Values(6,3,"海淀")
INSERTINTOArea(id,CityId,name)Values(7,3,"朝阳")
2.建立文件
建立文件CityData.asp
<%@LANGUAGE=VBSCRIPT%>
<%RSDispatch%>
<SCRIPTRUNAT=SERVERLanguage=javascript>
<!--#INCLUDEVIRTUAL="/_ScriptLibrary/RS.ASP"-->
<!--#INCLUDEVIRTUAL="/jsconn.asp"-->
functionDescription()
{
this.GetAreaAsArray=DoGetData;
}
public_description=newDescription();
functionDoGetData(cityId)
{
varsql,rst,strText,conn,i,j
conn=newActiveXObject("ADODB.Connection");
conn.ConnectionString=connstr;
conn.ConnectionTimeout=30;
conn.Open();
sql="Selectname,idfromareawherecityid=´"+cityId+"´";
rst=newActiveXObject("ADODB.Recordset");
rst.CursorLocation=3;
rst.Open(sql,conn);
i=0;
j=0;
strText=newArray();
if(rst.RecordCount>=1)
{
for(vari=0;i<rst.RecordCount;++i)
{
strText[j++]=rst.Fields("name").Value;
strText[j++]=rst.Fields("id").Value;
rst.movenext();
}
}
else
{
strText[j++]="没有";
strText[j++]=1;
}
rst.close();
conn.close();
returnstrText;
}
</SCRIPT>
建立文件jsconn.asp
<SCRIPTRUNAT=SERVERLanguage=javascript>
varconnstr="driver={SQLServer};server=202.0.0.108;uid=sa;pwd=;database=house";
</SCRIPT>
建立文件pub.asp
<%
FunctionOpenOrGet_Database
DimSessionName,conn
constconnstr="driver={SQLServer};server=202.0.0.108;uid=sa;pwd=;database=house"
SessionName="House"
IfNotIsObject(Session(SessionName))Then
Setconn=Server.CreateObject("ADODB.Connection")
conn.Openconnstr
SetSession(SessionName)=conn
EndIf
SetOpenOrGet_Database=Session(SessionName)
EndFunction
%>
建立文件sql_pub.asp
<%
´取出城市资料
FunctionSelectCity()
DimConn,Sql,Rs,ArrCity,TmpArr(1,0)
SetConn=OpenOrGet_Database
SetRs=Server.CreateObject("ADODB.Recordset")
Sql="Selectdistinctname,idfromCity"
Rs.OpenSql,Conn,3
ifRs.Eofthen
TmpArr(0,0)="城市"
TmpArr(1,0)=0
Rs.Close
SelectCity=TmpArr
else
ArrCity=RS.GetRows()
Rs.Close
SelectCity=ArrCity
endif
EndFunction
´根据传来的CityId取出相应的地区资料
FunctionSelectArea(CityId)
DimConn,Sql,Rs,ArrArea,TmpArr(1,0)
SetConn=OpenOrGet_Database
SetRs=Server.CreateObject("ADODB.Recordset")
Sql="Selectname,idfromAreawhereCityId="&CityId&"orderbyid"
Rs.OpenSql,Conn,3
ifRs.Eofthen
TmpArr(0,0)="地区"
TmpArr(1,0)=0
Rs.Close
SelectArea=TmpArr
else
ArrArea=RS.GetRows()
Rs.Close
SelectArea=ArrArea
endif
EndFunction
%>
建立文件test.asp
<%@LANGUAGE="VBSCRIPT"%>
<%optionexplicit%>
<!--#includeVIRTUAL="pub.asp"-->
<!--#includeVIRTUAL="Sql_pub.asp"-->
<%
DimarrCity,arrArea,strPathInfo,strServerName,strServerPort,i,TmpStr
strPathInfo=Request.ServerVariables("PATH_INFO")
strServerName=Request.ServerVariables("SERVER_NAME")
strServerPort=Request.ServerVariables("SERVER_PORT")
iflen(strServerPort)=0then
strServerPort=""
else
strServerPort=":"+strServerPort
endif
strPathInfo="http://"&strServerName&strServerPort&""
arrCity=SelectCity()
arrArea=SelectArea(arrCity(1,0))
%>
<html>
<head>
<title>UntitledDocument</title>
<metahttp-equiv="目录类型"content="文本/html;字符集=gb2312">
</head>
<scriptlanguage="JavaScript"src="<%=strPathInfo%>/_ScriptLibrary/rs.htm"></script>
<scriptlanguage="JavaScript">
RSEnableRemoteScripting("<%=strPathInfo%>/_ScriptLibrary");
</script>
<bodybgcolor="#FFFFFF">
<formmethod="post"name="select">
<fontcolor="#222200">
<selectname="City"size="1"onChange="JavaScript:Choosesection(this.form.Area,this.form.City)">
<optionvalue=0selected>--选择城市--</option>
<%fori=LBound(arrCity,2)ToUBound(arrCity,2)
TmpStr="<optionvalue="&arrCity(1,i)&""
TmpStr=TmpStr&">"&arrCity(0,i)&"</option>"
Response.Write(TmpStr)
Next
%>
</select>
</font><fontcolor="#222200">
<selectname="Area"size=1>
<optionvalue=0>--选择镇区--</option>
<%Fori=LBound(arrArea,2)ToUBound(arrArea,2)
ifarrArea(1,i)<>0then
%>
<optionvalue=<%=arrArea(1,i)%>><%=arrArea(0,i)%></option>
<%endif
Next%>
</select>
</font>
</form>
<scriptlanguage="JavaScript">
varserverURL="<%=strPathInfo%>";
varpageURL="/CityData.asp";
functionChoosesection(oArea,oCity)
{
for(vari=oArea.options.length-1;i>0;--i)
{oArea.options.remove(i)}
varCityId=oCity.options(oCity.selectedIndex).value;
varobjResult=RSExecute(serverURL+pageURL,"GetAreaAsArray",CityId);
varj=0
if(objResult.return_value.length>0)
{
for(vari=0;i<objResult.return_value.length/2;++i)
{
sName=objResult.return_value[j++];
sId=objResult.return_value[j++];
varoOption=document.createElement(´OPTION´);
oOption.text=sName;
oOption.value=sId;
oArea.options.add(oOption);
}
}
}
</script>
</body>
</html>
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
ajax可以实现局部刷新页面,即在不刷新整个页面的情况下更新页面的局部信息。项目中遇到一个问题:在用户列表也,当点击某个按钮时需要去查询用户的信息,查询成功跳转
history.pushState和history.replaceState可以在不刷新当前页面的情况下更改URL,但是这样就无法获取通过AJAX得到的新页面的
不带边框的iframe因为能和网页无缝的结合从而不刷新页面的情况下更新页面的部分数据成为可能,可是iframe的大小却不像层那样可以“伸缩自如”,所以带来了使用
首先要说的是,这是一个伪翻页。原理是调用例如100个数据后,将其后面的内容做隐藏处理,在不刷新页面的情况下进行内容的翻页。并且附带了渐入渐出效果。引入jQuer
ASP自动刷新页面的实现方法总结: 1) 10表示间隔10秒刷新一次 2) window.location.reload(true);