简体   繁体   English

ASP Classic-在JavaScript页面中包含VBScript页面?

[英]ASP Classic - Include VBScript page in a JavaScript page?

Is there a way to include a VBScript page into an ASP page written using Javascript? 有没有办法将VBScript页面包含在使用Javascript编写的ASP页面中?

There is an ASP page written in Javascript, but our sidebar menu is written in VBScript. 有一个用Javascript编写的ASP页,但是我们的侧边栏菜单是用VBScript编写的。 When I include the sidebar asp file into the Javascript the server gives an error. 当我在Javascript中包含侧边栏asp文件时,服务器给出错误。

< %@ LANGUAGE="JavaScript" %> <%@ LANGUAGE =“ JavaScript”%>

<% <%

... ...

< !--#include file="sidebar.asp"--> <!-#include file =“ sidebar.asp”->

... ...

where sidebar.asp is written using VBScript. 使用VBScript编写sidebar.asp的位置。

You can try this, but my guess is that the sidebar.asp will be executed before your Javascript code. 您可以尝试这样做,但是我的猜测是sidebar.asp将在您的Javascript代码之前执行。

< %@ LANGUAGE="JavaScript" %>

<%

...
<script language="VBscript" runat=server> 
< !--#include file="sidebar.asp"-->
</script> 
...

I do this all the time, but I write my ASP/JScript pages a bit differently. 我一直都这样做,但是我写的ASP / JScript页面却有所不同。 Instead of switching the page language to "JavaScript", I leave it at the default "VBScript" and then use a <SCRIPT LANGUAGE="JavaScript" RUNAT="Server"> block for my JScript code. 我没有将页面语言切换为“ JavaScript”,而是将其保留为默认的“ VBScript”,然后为我的JScript代码使用<SCRIPT LANGUAGE="JavaScript" RUNAT="Server">块。 The JavaScript SCRIPT blocks are executed before the normal <% %> tags, so I do all my page processing in the SCRIPT blocks and then simply plug the results into the page with <% %> tags. JavaScript SCRIPT块在普通的<% %>标记之前执行,因此我在SCRIPT块中进行了所有页面处理,然后只需将结果插入带有<% %>标记的页面中。 Here's an example: 这是一个例子:

mainpage.asp: mainpage.asp:

<SCRIPT LANGUAGE="JavaScript" RUNAT="Server">
var name;
var address;
var phone;
function main() {
    var rec = go_to_database();
    name = rec.first_name + " " + rec.last_name;
    address = rec.address;
    phone = rec.phone;
}
</SCRIPT><% main() %>
<html><head><title><%= name %></title></head><body>
<p>Name: <%= name %><br/>
Address: <%= address %><br/>
Phone Number: <%= phone %></p>
<!--#include file="subpage.asp"-->
</body></html>

subpage.asp: subpage.asp:

<p>Blah blah blah, some random VBScript code: <%
    Dim whatever
    whatever = some_silly_thing()
    Response.Write(whatever)
%>.</p>

So, first IIS processes the SSI and includes subpage.asp into mainpage.asp . 因此,首先IIS处理SSI,并将subpage.asp包含在mainpage.asp Then, it evaluates the JScript SCRIPT block, declaring the variables name , address , and phone and defining the function main . 然后,它评估JScript SCRIPT块,声明变量nameaddressphone并定义函数main

Then it evaluates each <% %> tag in order. 然后,它按顺序评估每个<% %>标签。 <% main() %> call the main function and sets values for name , address , and phone . <% main() %>调用main函数并设置nameaddressphone Then <%= name %> , <%= address %> , and <%= phone %> substitute those values into the page. 然后<%= name %><%= address %><%= phone %>将这些值替换为页面。 Finally, the <% %> code from subpage.asp is evaluated and the Response.Write value ends up in the page output. 最后,对subpage.asp<% %>代码进行评估,并且Response.Write值最终出现在页面输出中。

While the whole page is not written in JScript, the vast majority of the code can be, inside the SCRIPT block. 尽管整个页面不是用JScript编写的,但是绝大多数代码都可以在SCRIPT块中。 Would that work for you? 那对你有用吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM