获取当前会话值在JavaScript中? [英] Get Current Session Value in JavaScript?

查看:125
本文介绍了获取当前会话值在JavaScript中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我在浏览器中,但在两个不同的选项卡打开我的web应用程序的情况。

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

在我从应用程序注销一个标签,因此所有会话值变为零。而在另一个选项卡我点击了web应用的锚标记。在锚标记的jQuery的上单击事件我已经检查了会话值。在这里,我应该接受会话为空(因为我登出从另一个选项卡中的应用程序),但我正在逐渐会话值作为登录的用户(可能是因为没有刷新页面时)。

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).

我的想法是检查jQuery的会议,如果会议是空使应用程序注销,否则显示一个弹出页面。

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

下面是我的code获取会话值

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
   }

}))

如何在jQuery中获取当前会话的价值?

How can I get the current session value in jQuery?

推荐答案

这次会议是一个服务器端的东西,你不能使用jQuery访问它。
你可以写一个HTTP处理程序(将共享的SessionID如果有的话),并从那里使用 $。阿贾克斯返回值。

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.

这篇关于获取当前会话值在JavaScript中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆