使用 jquery 保存会话变量似乎不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14891615/
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-26 14:02:34  来源:igfitidea点击:

Saving session var with jquery doesn't seem to work

jquerysession

提问by Darren

I'm having trouble storing session...

我在存储会话时遇到问题...

Code I'm using:

我正在使用的代码:

//save to session
    $.session("compareLeftContent","value");
    alert($.session("compareLeftContent"));

http://jsfiddle.net/dWsKJ/to play with.

http://jsfiddle.net/dWsKJ/一起玩。

Please any ideas?

请问有什么想法吗?

回答by ?ukaszW.pl

On jsfiddle example you provided there is no session plugin attached. $.sessionis not included in jQuery. You need to use this plugin to have this functionality: Jquery Session Plugin

在您提供的 jsfiddle 示例中,没有附加会话插件。$.session不包含在 jQuery 中。你需要使用这个插件来拥有这个功能:Jquery Session Plugin

Then use $.session.setand $.session.getmethods to store and read session keys.

然后使用$.session.set$.session.get方法来存储和读取会话密钥。

example:

例子:

$.session.set("compareLeftContent","value");
alert($.session.get("compareLeftContent"));

回答by Darren

Are you using session.js?

你在使用 session.js 吗?

You need to set the session using $.session.set:

您需要使用$.session.set以下方法设置会话:

$.session.set("compareLeftContent", "value");

To retrieve the session value use $.session.get:

要检索会话值,请使用$.session.get

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