I write to cookies using jquery. I write down the user object, which has properties.

I write it this way: $.cookie('user', JSON.stringify(user), { expires: 7, path: '/' });

I see the following in cookies: %7B%22login%22%3A%22ADMIN%22%2C%22user_id%22%3A1%2C%22role%22%3A%22user%22%7D .

Tried to write without jquery writes fine. But I would like to use jquery cookie. Tell me how to fix this thing?

  • I do not understand what you do not like? - Alexey Ten
  • What is the problem? The plugin encodes all the "dangerous" characters in Percent-encoding ( en.wikipedia.org/wiki/Percent-encoding ), for the sake of security. - user207618
  • @AlexeyTen what it looks like. - Tsyklop
  • @Other tobish is this ok? - Tsyklop
  • @Other The problem is that I need to get this data in Filter (JavaEE). - Tsyklop

1 answer 1

Can use raw flag

 $.cookie.raw = true; 

Then, when writing / reading, the functions encodeURIComponent / decodeURIComponent will not be used decodeURIComponent

You can also use the json flag

 $.cookie.json = true; 

in this case, the call can be simplified to

 $.cookie('user', user, { expires: 7, path: '/' });