Jquery. Cookies operate cookies on different pages

Source: Internet
Author: User

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 :'/'});

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.