在 vbscript 的服务器标签中访问客户端变量
Access client variable within server-tags in vbscript
我在 运行 的 asp 页面中有以下代码块:
<script language="VBScript">
sub ok_onclick()
dim localVariable
localVariable= "hello"
<%
call serversideFunction(localVariable)
%>
end sub
以下区块
<% call ServerSideFunction(localVariable) %>
抛出以下错误:
An unhandled exception ('Variable is undefined: 'localVariable'')
occurred in dllhost.exe [24184]
我注意到我无法将局部变量放入服务器代码标签中。
所以我的问题是,如何将本地变量的值发送到服务器?
这是 Server-Side 编程 101,它有时确实会吸引人,但那里有很多很好的教程和文章可以帮助理解基础知识。
Quote from MSDN - ASP Overview
IIS processes an ASP file in the following order when a request is received from a client:
If an ISAPI filter is installed on the Web site, the ISAPI filters is processed first. This is true for all applications.
If the ASP application contains a Global.asa file in the root directory, the Global.asa is processed. Global.asa files specify event scripts and declare objects that have session or application scope. They do not display content; instead they stores event information and objects used globally by the ASP application.
In the requested ASP file, IIS separates the script blocks from the static HTML code blocks, reserving the static code in the response body.
IIS processes the script blocks. The script blocks might include transaction processing, database access calls, or calls to COM components in which case COM+ handles some of the processing.
After the ASP page script blocks are processed, their output is injected into the response body with the static HTML code.
The response is sent to the client.
问题归结为第 6 步。在提供的示例中,所有 server-side 处理都在将响应发送到客户端之前完成;
'Client-Side procedure
Sub ok_onclick()
dim localVariable
localVariable= "hello"
<%
'Server-Side code already processed before response
'is returned to the client.
Call serversideFunction(localVariable)
%>
End Sub
serversideFunction()
server-side 函数在发送客户端响应之前已经执行,因此永远不会知道 localVariable
.
的存在
在这些情况下,您需要使用各种久经考验的技术将 localVariable
数据传回服务器 (HTML 表单,AJAX 请求等) 这一切都归结为传达服务器可以解释和处理的 HTTP GET
或 HTTP POST
请求。
发送请求后,可以使用 ASP Request Object 获取数据并将其传递到 Server-side 变量中。
<%
Dim serverVariable
'Request came via a HTTP GET.
serverVariable = Request.QueryString("localVariable")
'Request came via a HTTP POST.
serverVariable = Request.Form("localVariable")
'Request came via either a HTTP GET or HTTP POST
'Using this has it's overheads.
serverVariable = Request("localVariable")
%>
有用的链接
我在 运行 的 asp 页面中有以下代码块:
<script language="VBScript">
sub ok_onclick()
dim localVariable
localVariable= "hello"
<%
call serversideFunction(localVariable)
%>
end sub
以下区块
<% call ServerSideFunction(localVariable) %>
抛出以下错误:
An unhandled exception ('Variable is undefined: 'localVariable'') occurred in dllhost.exe [24184]
我注意到我无法将局部变量放入服务器代码标签中。
所以我的问题是,如何将本地变量的值发送到服务器?
这是 Server-Side 编程 101,它有时确实会吸引人,但那里有很多很好的教程和文章可以帮助理解基础知识。
Quote from MSDN - ASP Overview
IIS processes an ASP file in the following order when a request is received from a client:
If an ISAPI filter is installed on the Web site, the ISAPI filters is processed first. This is true for all applications.
If the ASP application contains a Global.asa file in the root directory, the Global.asa is processed. Global.asa files specify event scripts and declare objects that have session or application scope. They do not display content; instead they stores event information and objects used globally by the ASP application.
In the requested ASP file, IIS separates the script blocks from the static HTML code blocks, reserving the static code in the response body.
IIS processes the script blocks. The script blocks might include transaction processing, database access calls, or calls to COM components in which case COM+ handles some of the processing.
After the ASP page script blocks are processed, their output is injected into the response body with the static HTML code.
The response is sent to the client.
问题归结为第 6 步。在提供的示例中,所有 server-side 处理都在将响应发送到客户端之前完成;
'Client-Side procedure
Sub ok_onclick()
dim localVariable
localVariable= "hello"
<%
'Server-Side code already processed before response
'is returned to the client.
Call serversideFunction(localVariable)
%>
End Sub
serversideFunction()
server-side 函数在发送客户端响应之前已经执行,因此永远不会知道 localVariable
.
在这些情况下,您需要使用各种久经考验的技术将 localVariable
数据传回服务器 (HTML 表单,AJAX 请求等) 这一切都归结为传达服务器可以解释和处理的 HTTP GET
或 HTTP POST
请求。
发送请求后,可以使用 ASP Request Object 获取数据并将其传递到 Server-side 变量中。
<%
Dim serverVariable
'Request came via a HTTP GET.
serverVariable = Request.QueryString("localVariable")
'Request came via a HTTP POST.
serverVariable = Request.Form("localVariable")
'Request came via either a HTTP GET or HTTP POST
'Using this has it's overheads.
serverVariable = Request("localVariable")
%>