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