Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting session value in javascript

I am using an external javascript file for my asp.net project. Now i want to get the session value in that javascript. How can i get the session value in that javascript file?

Thanks in advance..

like image 209
ZMR BINU Avatar asked Dec 06 '11 06:12

ZMR BINU


People also ask

Can I get session value in JavaScript?

Session is a variable on the backend server side, while JS is a previous script. There is no ready-made method in JS to get the value of Session, and it needs to be obtained through the server language. For example, java can be used to get the value of Session and assign it to JS variable.

How do you get a value stored in a session?

getItem(key): This method is used to get the value that is stored into the Session Storage. It takes a key and returns the value. removeItem(key): This method is used to remove a particular value from the Session Storage basis of the key. clear(): This method is used to clear the Session Storage.

How do you find the value of session variables?

You can check whether a variable has been set in a user's session using the function isset(), as you would a normal variable. Because the $_SESSION superglobal is only initialised once session_start() has been called, you need to call session_start() before using isset() on a session variable.

What is session in JavaScript?

Session storage is a popular choice when it comes to storing data on a browser. It enables developers to save and retrieve different values. Unlike local storage, session storage only keeps data for a particular session. The data is cleared once the user closes the browser window.


1 Answers

I tried following with ASP.NET MVC 5, its works for me

var sessionData = "@Session["SessionName"]";
like image 190
Kelum Avatar answered Oct 01 '22 20:10

Kelum