简体   繁体   中英

JS cookie: cannot set path

Both statements fail to set cookies path to the desired value:

 $.cookie('name', 'value', { path: "abc/de" });
 document.cookie = "username=John Smith; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=abc/de";

The actual path is always set to the controller:

在此处输入图片说明

Background: I have two kendo grids whose selected emelents I want to store in a cookie. Somehow I need to distinguish between both grids that only differ in path.

Shouldn't be this exactly what path is ment for?

See the specification :

If the attribute-name case-insensitively matches the string "Path", the user agent MUST process the cookie-av as follows.

If the attribute-value is empty or if the first character of the
attribute-value is not %x2F ("/"):

  Let cookie-path be the default-path. 

Otherwise:

  Let cookie-path be the attribute-value. 

Append an attribute to the cookie-attribute-list with an attribute- name of Path and an attribute-value of cookie-path.

Since the first character of your path is a and not / , the value is invalid and is ignored.

You must provide an absolute path (such as /foo/bar/abc/de ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM