Question

I want to create a cookie with:

  • Name: drm
  • Value: drmStatus=Expected

I'm using the code from the answer to this question - Jquery Cookie plugin - multiple values? to create the cookie

 var obj = { drmStatus: 'Expected' }; 
 $.cookie('drm', $.param(obj), { path: '/', raw: true })

However this generates a cookie with

  • Name: drm
  • Value: drmStatus%3DExpected

The reason for this is this snippet from https://github.com/carhartl/jquery-cookie/blob/master/jquery.cookie.js

config.raw ? value : encodeURIComponent(value)

This is using the value of "raw" from the config object to decide whether to encode the value. It appears to be ignoring the value of "raw" value passed in the options object.

So my question is, can I set the option raw: true when using jquery.cookie?

Was it helpful?

Solution

I think your problem is not in the jquery.cookie but in the $.param part of your script. See this JSFiddle. The raw option is set correctly and the cookie has your desired value.

This should work:

var obj = { drmStatus: 'Expected' }; 
$.cookie('drm', decodeURIComponent($.param(obj)), { path: '/', raw: true })

EDIT: I updated the Fiddle to work with your new version. The solution is:

var obj = { drmStatus: 'Expected' }; 
$.cookie.raw = true;
$.cookie('drm', $.param(obj), { path: '/' });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top