admin管理员组文章数量:1316660
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 02 Answers
Reset to default 4All 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>
本文标签: asp classicHow to get a session variable via javascript from an asp server scriptStack Overflow
版权声明:本文标题:asp classic - How to get a session variable via javascript from an asp server script - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741999889a2410795.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论