Solution to Js failure to read cookie

Source: Internet
Author: User

Problem description:

You need to use a cross-origin cookie and cannot set or read the cookie.

The cookie uses jquery cookie. Download Address: http://plugins.jquery.com/cookie /.

To be honest, the official method of use is really incomprehensible. Fortunately, it is awesome for netizens.

Briefly describe the usage method:

Write cookie:

$. Cookie ('php', 'phpdo ');

Read cookie:

$. Cookie ('php'); // cookie existence => 'phpdo'

Delete cookie:

Pass null as the cookie value.

$. Cookie ('php', null );

My cookie: $. cookie ("name", name, {path: '/', domain: 'uelife. Cn', secure: true });

After searching for half a day, no problem was found. During the tangle, I accidentally saw the parameter again. Open.

Secure: true: if it is true, secure protocol (HTTPS) is required for cookie transmission ).

The web I use is http, but it cannot be opened.

Okay. Today, a hand owe error still occurred.

Parameters:
1). expires: 365

Defines the effective time of a cookie. The value can be a number (counted from the cookie creation time, in days) or a Date object. If this parameter is omitted, the created cookie is a session cookie and will be deleted when the user exits the browser.

2). path :'/'

Default: only webpages with cookie settings can read the cookie.

Defines the valid cookie path. By default, the value of this parameter is the path of the page where the cookie is created (the behavior of the standard browser ).

If you want to access this cookie on the entire website, you need to set the valid path as follows: path :'/'.

If you want to delete a cookie that defines a valid path, you need to include this path when calling the function: $. cookie ('php', phpdo, {path :'/'});.

Domain: 'phpdo. Net'

Default value: the domain name of the webpage for which the cookie is created.

3). secure: true

Default value: false. If the value is true, the secure protocol (HTTPS) is required for cookie transmission ).

4). raw: true

Default value: false.

By default, the system automatically performs encoding and decoding (encodeURIComponent encoding and decodeURIComponent decoding) when reading and writing cookies ). To disable this function, set raw: true.

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.