Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

session handling in jquery

Tags:

jquery

I am using following code to store value in session object in jQuery but i get error $.session function is not a function.

I also add plugin "jquery.session.js" from githhub site but it is not work. Pls let me help out what's wrong

 // To Store
 $(function() {
      $.session("myVar", "value");
 });


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

If there is any other way to do this...then also tell me.....

like image 963
user1206218 Avatar asked Jul 20 '12 13:07

user1206218


2 Answers

In my opinion you should not load and use plugins you don't have to. This particular jQuery plugin doesn't give you anything since directly using the JavaScript sessionStorage object is exactly the same level of complexity. Nor, does the plugin provide some easier way to interact with other jQuery functionality. In addition the practice of using a plugin discourages a deep understanding of how something works. sessionStorage should be used only if its understood. If its understood, then using the jQuery plugin is actually MORE effort.

Consider using sessionStorage directly: https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Storage#sessionStorage

like image 89
ktamlyn Avatar answered Oct 06 '22 01:10

ktamlyn


Assuming you're referring to this plugin, your code should be:

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


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

Before using a plugin, remember to read its documentation in order to learn how to use it. In this case, an usage example can be found in the README.markdown file, which is displayed on the project page.

like image 38
Frédéric Hamidi Avatar answered Oct 06 '22 01:10

Frédéric Hamidi