From http://www.cnblogs.com/amethyst8989/archive/2009/09/02/1558890.html
Jquery. Usage of cookies [for your own memory only]
Http://plugins.jquery.com/files/jquery.cookie.js.txt
Some time ago, I used jquery cookie to make a shopping cart. During the process, I encountered a problem that when I stored cookies on different pages, it was not the same cookie for operations, so that two identical names exist in the cookie.
The solution is to add the expiration time and Path in each cookie. For example: $. Cookie ('products', newcookies, {expires: 7, path :'/'});
The problem is solved.
Get COOKIE: var allcookies = $. Cookie ('products'); // products is the cookie name
Generate a new COOKIE: var newcookies = "";
If ($. Cookie ('products') = NULL ){
Newcookies + = commodityid + "|" + Type + "= 1"; // assign a value to the cookie
$. Cookie ('products', newcookies, {expires: 7, path: '/'}); // reset the cookie value named Product
}
$. Cookie ('products', '', {expires:-1, path :'/'});
Http://plugins.jquery.com/files/jquery.cookie.js.txt
Some time ago, I used jquery cookie to make a shopping cart. During the process, I encountered a problem that when I stored cookies on different pages, it was not the same cookie for operations, so that two identical names exist in the cookie.
The solution is to add the expiration time and Path in each cookie. For example: $. Cookie ('products', newcookies, {expires: 7, path :'/'});
The problem is solved.
Get COOKIE: var allcookies = $. Cookie ('products'); // products is the cookie name
Generate a new COOKIE: var newcookies = "";
If ($. Cookie ('products') = NULL ){
Newcookies + = commodityid + "|" + Type + "= 1"; // assign a value to the cookie
$. Cookie ('products', newcookies, {expires: 7, path: '/'}); // reset the cookie value named Product
}
$. Cookie ('products', '', {expires:-1, path :'/'});