Invoke remote ASP scripts without refreshing the page application tips

Source: Internet
Author: User
1. Please build a database in SQL Server name:house run the following script in house

if exists (select * from sysobjects where id = object_id (n´[dbo].[ City]´) and OBJECTPROPERTY (ID, N´isusertable´) = 1)
drop table [dbo]. [City]
Go

if exists (select * from sysobjects where id = object_id (n´[dbo].[ Area]´) and OBJECTPROPERTY (ID, N´isusertable´) = 1)
drop table [dbo]. [Area]
Go

CREATE TABLE [dbo]. [City] (
[ID] [int] IDENTITY (1, 1) not NULL,
[Name] [nvarchar] (Ten) NULL
) on [PRIMARY]
Go

CREATE TABLE [dbo]. [Area] (
[ID] [int] IDENTITY (1, 1) not NULL,
[Cityid] [INT] Null
[Name] [nvarchar] (a) NULL
) on [PRIMARY]
Go

INSERT into City (id,name) Values (1, "Guangzhou")
INSERT into City (id,name) Values (2, "Shanghai")
INSERT into City (id,name) Values (3, "Beijing")

INSERT into Area (id,cityid,name) Values (1, 1, "Tianhe")
INSERT into Area (id,cityid,name) Values (2,1, "white Clouds")
INSERT into Area (id,cityid,name) Values (3,2, "Hongkou")
INSERT into Area (id,cityid,name) Values (4,2, "Baoshan")
INSERT into Area (id,cityid,name) Values (5,2, "Jingan")
INSERT into Area (id,cityid,name) Values (6,3, "Haidian")
INSERT into Area (id,cityid,name) Values (7,3, "Chaoyang")

2. Establishment of documents

Create a file citydata.asp
<%@ Language=vbscript%>
<% RSDispatch%>

<script Runat=server language=javascript>
<!--#INCLUDE virtual= "/_scriptlibrary/rs. ASP "-->
<!--#INCLUDE virtual= "/jsconn.asp"-->

function Description ()
{
This. Getareaasarray = Dogetdata;
}
public_description = new description ();


function Dogetdata (Cityid)
{
var sql,rst,strtext,conn,i,j
conn = new ActiveXObject ("ADODB. Connection ");
Conn. ConnectionString = ConnStr;
Conn. ConnectionTimeout = 30;
Conn. Open ();
sql = "Select Name,id from area where Cityid=´" + Cityid + "´";
rst = new ActiveXObject ("ADODB.") Recordset ");
Rst. CursorLocation = 3;

Rst. Open (Sql,conn);
i = 0;
j = 0;
StrText = new Array ();

if (rst. RecordCount >= 1)
{
For (Var i=0;i<rst. Recordcount;++i)
{
Strtext[j++] = rst. Fields ("name"). Value;
Strtext[j++] = rst. Fields ("id"). Value;
Rst.movenext ();
}
}
Else
{
Strtext[j++] = "no";
Strtext[j++] = 1;
}
Rst.close ();
Conn.close ();
return strText;
}
</SCRIPT>

Create a file jsconn.asp

<script Runat=server language=javascript>
var connstr = "Driver={sql Server}"; server=202.0.0.108;uid=sa;pwd=;d Atabase=house ";
</SCRIPT>

Create a file pub.asp
<%

Function Openorget_database
Dim SessionName, Conn
Const CONNSTR = "Driver={sql Server}"; server=202.0.0.108;uid=sa;pwd=;d Atabase=house "
SessionName = "House"
If not IsObject (session (sessionname)) Then
Set conn = Server.CreateObject ("ADODB. Connection ")
Conn. Open ConnStr
Set session (SESSIONNAME) = conn
End If
Set openorget_database = Session (sessionname)
End Function



%>

Create a file sql_pub.asp
<%


´ take out the city information
Function selectcity ()
Dim Conn, SQL, Rs, Arrcity, Tmparr (1,0)
Set Conn = openorget_database
Set Rs = Server.CreateObject ("ADODB.") Recordset ")
SQL = "SELECT distinct name,id from City"
Rs.Open sql,conn,3
If Rs.eof Then
Tmparr (0,0) = "City"
Tmparr (1,0) = 0
Rs.close
Selectcity = Tmparr
Else
Arrcity = RS. GetRows ()
Rs.close
Selectcity = arrcity
End If
End Function

´ according to the Cityid to remove the corresponding regional information
Function Selectarea (Cityid)
Dim Conn, SQL, Rs, Arrarea, Tmparr (1,0)
Set Conn = openorget_database
Set Rs = Server.CreateObject ("ADODB.") Recordset ")
SQL = ' Select Name,id from area where cityid= ' & Cityid & ' ORDER by ID '
Rs.Open sql,conn,3
If Rs.eof Then
Tmparr (0,0) = "Region"
Tmparr (1,0) = 0
Rs.close
Selectarea = Tmparr
Else
Arrarea = RS. GetRows ()
Rs.close
Selectarea = Arrarea
End If
End Function


%>

Create a file test.asp
<%@ language= "VBSCRIPT"%>
<%option explicit%>
<!--#include virtual= "pub.asp"-->
<!--#include virtual= "sql_pub.asp"-->
<%
Dim arrcity, Arrarea, Strpathinfo, strServerName, Strserverport, I, tmpstr

Strpathinfo = Request.ServerVariables ("Path_info")
strServerName = Request.ServerVariables ("SERVER_NAME")
Strserverport = Request.ServerVariables ("Server_port")
If Len (strserverport) = 0 Then
Strserverport = ""
Else
Strserverport = ":" + strserverport
End If
Strpathinfo = "http://" & strServerName & Strserverport & ""

Arrcity = Selectcity ()
Arrarea = Selectarea (arrcity (1,0))


%>

<title>untitled document</title>
<meta http-equiv= "directory Type" content= "text/html; Character Set =gb2312 ">
<script language= "JavaScript" src= "<%=strpathinfo%>/_scriptlibrary/rs.htm" ></script>
<script language= "JavaScript" >
Rsenableremotescripting ("<%=strpathinfo%>/_scriptlibrary");
</script>

<body bgcolor= "#FFFFFF" >
<form method= "POST" name= "select" >
<font color= "#222200" >
<select name= "City" size= "1" onchange= "Javascript:choosesection (this.form.area,this.form.city)" >
<option value=0 selected>--Select City--</option>
<%for i = LBound (arrcity,2) to UBound (arrcity,2)
Tmpstr = "<option value=" & Arrcity (1,i) & ""
TMPSTR = tmpstr & ">" & Arrcity (0,i) & "</option>"
Response.Write (TMPSTR)
Next
%>
</select>
</font><font color= "#222200" >
<select name= "Area" size=1>
<option value=0>--Select Town Area--</option>
<%for i = LBound (arrarea,2) to UBound (arrarea,2)
If Arrarea (1,i) <>0 Then
%>
<option Value=<%=arrarea (1,i)%>><%=arrarea (0,i)%></option>
<% End If
Next%>
</select>

</font>
</form>
<script language= "JavaScript" >
var ServerURL = "<%=strPathInfo%>";
var pageurl = "/citydata.asp";
function Choosesection (oarea,ocity)
{
for (Var i=oarea.options.length-1;i>0;--i)
{OArea.options.remove (i)}
var Cityid = ocity.options (ocity.selectedindex). value;
var objresult = Rsexecute (Serverurl+pageurl, "Getareaasarray", Cityid);
var j=0
if (objresult.return_value.length>0)
{
for (var i=0; i<objresult.return_value.length/2;++i)
{
sname = objresult.return_value[j++];
SId = objresult.return_value[j++];
var ooption = document.createelement (´option´);
Ooption.text = sname;
Ooption.value = sId;
OArea.options.add (ooption);
}
}

}

</script>
</body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.