开发者

JQuery.cookies setting a key value pair

开发者 https://www.devze.com 2022-12-18 23:27 出处:网络
I\'m trying to use the JQuery cookies library http://code.google.com/p/cookies/ But am not able to set key value 开发者_运维百科pairs within the cookie. I can\'t see how in the documentation, does any

I'm trying to use the JQuery cookies library http://code.google.com/p/cookies/ But am not able to set key value 开发者_运维百科pairs within the cookie. I can't see how in the documentation, does anyone know how?

Thanks


Check out the JSON example in the link you referenced.

//JSON 
var jimData = {id: 1, name: 'jim'}; 
$.cookies.set( 'userdata', jimData ); //A cookie by the name 'userdata' now exists with a serialized copy of jimData 

var userData = $.cookies.get( 'userdata' ); //A variable named 'userData' now holds the unserialized object--should be identical to the variable 'jimData' 

So, userData should now have properties id with value 1 and name with value 'jim'.

0

精彩评论

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