質問

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?

役に立ちましたか?

解決

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: '/' });
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top