最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how can I create session in jquery? - Stack Overflow

programmeradmin3浏览0评论

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.

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

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

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.

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

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

Share Improve this question asked Jul 13, 2016 at 6:32 Aasiya MairajAasiya Mairaj 1851 gold badge3 silver badges17 bronze badges 3
  • try sessionStorage.setItem('rmng_time', remaining_seconds); – Amar Singh Commented Jul 13, 2016 at 6:35
  • which means the plugin is not loaded. check if jquery is loaded. if jquery is loaded then check jquery.session is loaded – Cerlin Commented Jul 13, 2016 at 6:46
  • i check every thing is fine but TypeError: $.session is undefined is showing – Aasiya Mairaj Commented Jul 13, 2016 at 8:53
Add a comment  | 

5 Answers 5

Reset to default 5

You need to reffer this tutorial:

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"));

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

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

Try :

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


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

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/

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

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

sessionStorage.loginData

发布评论

评论列表(0)

  1. 暂无评论