开发者

How to retrieve a specific cookie value if it has multiple values using JavaScript?

开发者 https://www.devze.com 2023-02-24 22:51 出处:网络
I\'m using jquery and I was wondering how do I retrieve a certain cookie value if I have multiple values, something like this:

I'm using jquery and I was wondering how do I retrieve a certain cookie value if I have multiple values, something like this:

$.cookie("name",[email,loc], { path: '/', ex开发者_Python百科pires: 60 });

How do I retrieve loc value?

Note: email and loc are set as variables.

I know you can get values by

$.cookie("name");

but i just want loc, not email and loc.


Try $.cookie("name")[1]. But nobody can tell you for sure without knowing which plugin you are using (it has to do some serializing/deserializing since cookies only contain plaintext - no arrays, objects, etc).


That looks like jQuery's plugin. See the json section of https://github.com/carhartl/jquery-cookie/blob/master/README.md on multiple values. You'd have to use curly instead of list brackets.

On the other hand you could parse the string yourself or create several cookies.

0

精彩评论

暂无评论...
验证码 换一张
取 消