手机
当前位置:查字典教程网 >编程开发 >ASP教程 >在不刷新页面的情况下调用远程asp脚本
在不刷新页面的情况下调用远程asp脚本
摘要:1.请在sqlserver中建一数据库name:house在house中运行下列脚本ifexists(select*fromsysobjec...

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>

<>

<>

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%>

<>

<>

<%

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>

【在不刷新页面的情况下调用远程asp脚本】相关文章:

如何回到先前的页面的方法多中语言 原创

ASP中的EVAL函数使用教程

虚拟主机重启代码

获取远程flash并保存到本地

大数量查询分页显示 微软的解决办法

在ASP中调用存储过程的几种方法

flash和asp分页的一点心得与flash脚本

ASP编程入门进阶(一):安装配置服务器

asp分页的一个类

写了段批量抓取某个列表页的东东

精品推荐
分类导航