1

I'm a beginner in jQuery.
I want to set the values in an HTML page and I have to get them in another HTML page.

Here is the piece of code I am trying now:

To set the value in session:

$.session.set(userName, $("#uname").val());

To get the value from session:

$.session.get('userName');
George Kagan
  • 5,913
  • 8
  • 46
  • 50
Sharath Kumar
  • 145
  • 3
  • 4
  • 11

2 Answers2

12

Assuming you are using this plugin, you are misusing the .set method. .set must be passed the name of the key as a string as well as the value. I suppose you meant to write:

$.session.set("userName", $("#uname").val());

This sets the userName key in session storage to the value of the input, and allows you to retrieve it using:

$.session.get('userName');
Asad Saeeduddin
  • 46,193
  • 6
  • 90
  • 139
3

Sessions are stored on the server and are set from server side code, not client side code such as JavaScript.

What you want is a cookie, someone's given a brilliant explanation in this Stack Overflow question here: How do I set/unset cookie with jQuery?

You could potentially use sessions and set/retrieve them with jQuery and AJAX, but it's complete overkill if Cookies will do the trick.

Community
  • 1
  • 1
Interwebtual
  • 136
  • 3