Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
206 views
in Technique[技术] by (71.8m points)

jquery - Get Current Session Value in JavaScript?

I have a scenario where I open my web application in a browser but in two separate tabs.

In one tab I signed out from the application and as a result the all session values becomes null. While in the other tab I clicked on an anchor tag in the webapplication. In the anchor tag's jquery-on click event I have checked the session value. Here I am supposed to get the session as null(since I logged out the application from the other tab), but I am getting session value as logged in user(probably because no page refresh occurs).

My idea is to check the session on jQuery and if the session is null make the application logout,otherwise show a popup page..

Here's my code for getting the session value

$(".a".click(function(){
   var session=var data = '@Session["UserName"]';
   if(session!=null){
    //Show popup
   }
   else{
    //Show loginpage
   }

}))

How can I get the current session value in jQuery?

question from:https://stackoverflow.com/questions/23538834/get-current-session-value-in-javascript

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The session is a server side thing, you cannot access it using jQuery. You can write an Http handler (that will share the sessionid if any) and return the value from there using $.ajax.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...