LoginSignup
6
4

More than 5 years have passed since last update.

jQuery.cookie.jsでクッキー名(キー)が内部でencodeURIComponentされている事実

Posted at

現象

ちょっと特殊な状況ですが、
hoge[fuga] というキーに 1 が入っているとする

うまく動かない例

console.log($.cookie('hoge[fuga]')); // undefined

なぜ?

hoge[fuga] が、内部で encodeURIComponent されて
hoge%5bfuga%5dと解釈されてしまっているから。

FYI: carhart/jquery-cookie - README

解決策

$.cookie.raw = true を使う

$.cookie.raw = true
console.log($.cookie('hoge[fuga]')); // 1

リンク

個人的な感想

普段あまり意識していなかっただけにハマった…。

6
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4