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

发布于 2024-08-13 16:50:18 字数 332 浏览 3 评论 0原文

有没有办法将 VBScript 页面包含到使用 Javascript 编写的 ASP 页面中?

有一个用 Javascript 编写的 ASP 页面,但我们的侧边栏菜单是用 VBScript 编写的。当我将侧边栏 asp 文件包含到 Javascript 中时,服务器给出错误。

< %@ LANGUAGE="JavaScript" %>

<%

...

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

...

其中 sidebar.asp 是使用 VBScript 编写的。

Is there a way to include a VBScript page into an ASP page written using Javascript?

There is an ASP page written in Javascript, but our sidebar menu is written in VBScript. When I include the sidebar asp file into the Javascript the server gives an error.

< %@ LANGUAGE="JavaScript" %>

<%

...

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

...

where sidebar.asp is written using VBScript.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瀟灑尐姊 2024-08-20 16:50:18

你可以尝试这个,但我的猜测是 sidebar.asp 将在你的 Javascript 代码之前执行。

< %@ LANGUAGE="JavaScript" %>

<%

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

You can try this, but my guess is that the sidebar.asp will be executed before your Javascript code.

< %@ LANGUAGE="JavaScript" %>

<%

...
<script language="VBscript" runat=server> 
< !--#include file="sidebar.asp"-->
</script> 
...
过期情话 2024-08-20 16:50:18

我一直这样做,但我编写 ASP/JScript 页面的方式有点不同。我没有将页面语言切换为“JavaScript”,而是将其保留为默认的“VBScript”,然后为 JScript 使用

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:

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

因此,首先 IIS 处理 SSI 并将 subpage.asp 包含到 mainpage.asp 中。然后,它评估 JScript SCRIPT 块,声明变量 nameaddressphone 并定义函数主要

然后它按顺序评估每个 <% %> 标记。 <% main() %> 调用 main 函数并设置 nameaddress电话。然后用 <%= name %><%= address %><%=phone %> 替换将这些值放入页面中。最后,对 subpage.asp 中的 <% %> 代码进行求值,并且 Response.Write 值最终出现在页面输出中。

虽然整个页面不是用 JScript 编写的,但绝大多数代码可以在 SCRIPT 块内编写。这对你有用吗?

I do this all the time, but I write my ASP/JScript pages a bit differently. 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. 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. Here's an example:

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:

<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. Then, it evaluates the JScript SCRIPT block, declaring the variables name, address, and phone and defining the function main.

Then it evaluates each <% %> tag in order. <% main() %> call the main function and sets values for name, address, and phone. Then <%= name %>, <%= address %>, and <%= phone %> substitute those values into the page. Finally, the <% %> code from subpage.asp is evaluated and the Response.Write value ends up in the page output.

While the whole page is not written in JScript, the vast majority of the code can be, inside the SCRIPT block. Would that work for you?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文