最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

asp classic - How to get a session variable via javascript from an asp server script - Stack Overflow

programmeradmin0浏览0评论

I'm new to the javascript world and have a simple test to read session vars in javascript:

my asp file:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Session("id")=1234
Session("code")="ZZ"
%>

my html file:

<html>
<head></head>
<body>
<script type="text/javascript" src="asp/testSession.asp">
    alert("Session ID " + Session("id"));
</script>
</body>

What am I doing wrong?

I'm new to the javascript world and have a simple test to read session vars in javascript:

my asp file:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Session("id")=1234
Session("code")="ZZ"
%>

my html file:

<html>
<head></head>
<body>
<script type="text/javascript" src="asp/testSession.asp">
    alert("Session ID " + Session("id"));
</script>
</body>

What am I doing wrong?

Share Improve this question asked Apr 10, 2013 at 12:57 user2225394user2225394 251 gold badge1 silver badge3 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 4

All ASP code has to be placed between <% and %> tags to be processed server-side:

alert("Session ID " + <%=Session("id") %>);
                      ^^^ add tags     ^^

Also, you can use <%= as a shortcut to output a variable. It's short for Response.Write.

You cannot mix javascript and asp in the way you did it. Javascript is executed locally while asp is piled by the server and then send to your browser.

When the page reaches your browser, only the product of the asp pilation remains. In order to use the value or print it, you should do the following :

<html>
<head></head>
<body>
<script type="text/javascript" src="asp/testSession.asp">
    alert("Session ID " + <%=Session("id")%>);
</script>
</body>
发布评论

评论列表(0)

  1. 暂无评论