Javascript 如何在 jquery 中创建会话?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38344181/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 21:22:01  来源:igfitidea点击:

how can I create session in jquery?

javascriptphpjquerysession

提问by Aasiya Mairaj

Here is my code. jquery.session.js file is also loaded I could not get where is the problem. Can you Please tell me the solution.

这是我的代码。jquery.session.js 文件也加载了我找不到问题出在哪里。你能告诉我解决方案吗。

$.session.set('rmng_time', remaining_seconds);
        alert("j session  "+$.session.get('rmng_time'));

this code gives an error in console TypeError: $.session is undefined

此代码在控制台 TypeError 中给出错误:$.session 未定义

回答by Dhara Parmar

You need to reffer this tutorial:

您需要参考本教程:

http://phprocks.letsnurture.com/create-session-with-jquery/

http://phprocks.letsnurture.com/create-session-with-jquery/

Add required files and refer code -

添加所需文件并参考代码 -

jquery-1.9.1.js and jquery.session.js

ex.

前任。

To set session:

设置会话:

$(function() {
 $.session.set("myVar", "Hello World!");
});

To get session:

获取会话:

alert($.session.get("myVar"));

回答by Mr. G

You can use jQuery session. See here in the docs.

您可以使用 jQuery 会话。请参阅文档中的此处。

$.session.set('some key', value);
console.log($.session.get('mobile_no'));

回答by Ashish Bhuyan

You can store the some specific data to the active session like sessionStorage.setItem("loginData",JSON.stringify(logObj));

您可以将一些特定数据存储到活动会话中,例如 sessionStorage.setItem("loginData",JSON.stringify(logObj));

And you can access the the stored data from the session like :-

您可以从会话中访问存储的数据,例如:-

sessionStorage.loginData

sessionStorage.loginData

回答by Rajkumar R

First you have to include the jquery session library files to run the $.session. so, follow this link http://code.ciphertrick.com/2015/01/20/session-handling-using-jquery/

首先,您必须包含 jquery 会话库文件以运行 $.session。所以,按照这个链接http://code.ciphertrick.com/2015/01/20/session-handling-using-jquery/

回答by rad11

Try :

尝试 :

$(function() {
    $.session.set("myVar", "value");
});


// To Read
$(function() {
    alert($.session.get("myVar"));
});