Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
asp.net中的jquery设置会话_Jquery_Asp.net_Session - Fatal编程技术网

asp.net中的jquery设置会话

asp.net中的jquery设置会话,jquery,asp.net,session,Jquery,Asp.net,Session,我正在尝试在jquery中设置会话。这是代码,但我想不出来。请看评论下面的一行。我怎么做 $(document).ready(function () { $("#demo-input-facebook-theme").tokenInput("http://xxx.com/MedService.aspx", { onAdd: function (item) { // *************************************

我正在尝试在jquery中设置会话。这是代码,但我想不出来。请看评论下面的一行。我怎么做

$(document).ready(function () {
    $("#demo-input-facebook-theme").tokenInput("http://xxx.com/MedService.aspx", {
        onAdd: function (item) {
            // *************************************
            // I want to add item.name to below code
            // *************************************
            <% HttpContext.Current.Session["Session_Post_Kategori"] += "item.name"; %>
        },
        onDelete: function (item) { },
        theme: "facebook"
     });
});
$(文档).ready(函数(){
$(“#演示输入facebook主题”).tokenInput(“http://xxx.com/MedService.aspx", {
onAdd:功能(项目){
// *************************************
//我想在下面的代码中添加item.name
// *************************************
},
onDelete:函数(项){},
主题:“facebook”
});
});
asp.net中的jquery设置会话


无法使用jQuery/javascript在客户端设置会话。会话在服务器端维护,并且必须在服务器端而不是jQuery中设置,尽管可以在jQuery中使用sessoin值。您可以向服务器发送一个ajax调用,以便从javascript设置会话。

会话存储在服务器端。。。Javascript/Jquery是客户端脚本。。所以您无法从Javascript访问会话。。。但是,您可以使用将值发布到服务器并存储在那里

例如

 onAdd: function (item) {
     $.post(yoururl,{data:item.name});//<--- this will post the data to your url (controller) and you can set the session there
onAdd:功能(项){

$.post(您的URL,{data:item.name});//无法将会话客户端设置为将在页面加载时执行,并将与HTML的其余部分一起呈现。但是,您可以使用它读取值并基于它执行某些操作。您可能想尝试@Adil所说的


我希望它能把一切都说得很清楚。

你不能试着去设置

您可以创建一个
通用http处理程序

从jquery调用它
在该处理程序中设置会话值

public class AddSalesLead : IHttpHandler, IRequiresSessionState
{
    public void ProcessRequest(HttpContext context)
    {
        context.Response.Session= context.Request["yourvalue"];
    }
    public bool IsReusable
    {
        get{return false;}
    }
}
并从jquery调用它

$(document).ready(function () {
    $("#demo-input-facebook-theme").tokenInput("http://xxx.com/MedService.aspx", {
        onAdd: function (item) {
          //call the handler here to set session value
          $.ajax({
               type: "POST",
               url: "yourhandler.ashx?yourvalue="+"value",
               success: function (data) {
               },
               error: function () {
               },
                async: true
           });
        },
        onDelete: function (item) { },
        theme: "facebook"
     });
});
编辑1 这里有一些链接


我发现这个网页对解决这个问题非常有帮助。它工作完美,非常干净。 它可以帮助避免通过会话或cookie


会话可以在Jquery中完美设置。通过Jquery的webmethod调用设置会话没有什么区别,因为Jquery调用的webmethod不属于对象。我在客户端说过“不能使用Jquery/javascript在客户端设置会话”web方法在服务器上?您在查询中传递的任何内容都将在处理程序中的会话中设置。首先,您创建一个
通用http处理程序
,您可以通过jquery调用它。我提供了一些链接。请参阅我的答案