Reputation: 1668
In my application when the user is login the particular user id
is stored in the session. I want to get this id
in a js
file.In this js
file contain state provider,factory etc
js
var sessionValue = "'"+<%=Session["userId"]%>+"'"
alert(sessionValue)
But it is show some error(Unexpected
)
Upvotes: 2
Views: 3230
Reputation: 495
I think that the problem is that your webserver
isn't evaluating as ASP
.js
files. You have three different way to get what you want
< script src="mysite/getjavascript.asp" >
Remember to print proper headers before printing your javascript
Upvotes: 0
Reputation: 4309
1.You can assign session value to hidden field.
<input type="hidden" name="userId" id="userId" value="<%= Session["userId"] %>">
function GetUserId()
{
var userId = document.getElementById('userId').value;
alert(userId);
}
Upvotes: 1
Reputation: 3492
You can use something like
<script type="text/javascript">
function GetUserId()
{
var userId = '<%= Session["userId"] %>';
alert(userId);
}
</script>
Upvotes: 0