未捕获的ReferenceError:未定义会话 [英] Uncaught ReferenceError: Session is not defined

查看:103
本文介绍了未捕获的ReferenceError:未定义会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这个下拉菜单



 out.println(< select name = \drplistalbum \onmousedown = \this.value =''; \onchange = \jsFunction(this.value); \>); 





和我的javascript是



 <   script    类型  ='  text / javascript' < span class =code-keyword>>  
function jsFunction(value)
{
// alert(value);
Session [drpname] = value;
}
< / script >





但我收到错误



未捕获的ReferenceError:未定义会话

解决方案

会话是服务器概念,而不是客户端:会话仅在C#或VB代码中运行代码背后。会话数据在Javascript中不可用。



我建议如果你在Javascript中需要这种功能,你应该考虑使用cookie。


 <   script     type   =  text / javascript >  
函数SetUserName()
{
var userName =Shekhar Shete ;
'<%会话[ UserName ] = '+ userName +'; %> ';
alert('<% =会话[ UserName] %> ');
}
< / script >


i made a dropdown using this

out.println("<select name=\"drplistalbum\" onmousedown=\"this.value='';\" onchange=\"jsFunction(this.value);\">");



and my javascript is

<script type='text/javascript'>
                 function jsFunction(value)
                 {
       //                      alert(value);
                      Session["drpname"] = value;
                 }
                     </script>



but i get an error

Uncaught ReferenceError: Session is not defined

解决方案

Session is a Server concept, not a Client: the Session is only available within the C# or VB code that runs in the code behind. The Session data is not available in Javascript.

I'd suggest that if you need this kind of function in Javascript, you should look at using cookies instead.


 <script type="text/javascript">
function SetUserName()
{
    var userName = "Shekhar Shete";
    '<%Session["UserName"] = "' + userName + '"; %>';
     alert('<%=Session["UserName"] %>');
}
</script>


这篇关于未捕获的ReferenceError:未定义会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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