Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a cookie using jquery to store name/value pairs of information

Tags:

jquery

cookies

I need to store a cookie that has the following information:

key1: datetime key2: datetime key3: datetime

How can i create and access the cookie with the above properties?

I need to manipulate this cookie via javascript (I am using jquery).

(side question, javascript cookie work is 'live' correct? i.e. it doesn't need a postback to change cookie values etc?)

like image 377
mrblah Avatar asked Oct 19 '09 13:10

mrblah


2 Answers

  • You don't need jQuery to read/write cookies. You can use plain javascript. Some good examples are here: http://www.quirksmode.org/js/cookies.html

  • You can use this jQuery plugin to make getting and setting cookies a little easier:

    http://plugins.jquery.com/project/Cookie

  • And yes, read/writing cookies is a live action as you mentioned.
like image 92
brendan Avatar answered Sep 28 '22 18:09

brendan


  1. jQuery Cookies plugin makes life easy.

  2. Cookies live on the client's computer, not the server. There is no need to postback when manipulating cookies.

like image 43
Matt Ball Avatar answered Sep 28 '22 17:09

Matt Ball