admin管理员组文章数量:1425902
I'm using external library, jquery.cookies.2.2.0.min.js
, and according to the documentation you get a list of all cookies like so.
jaaulde.utils.cookies.filter( /^site/ );
returns list of cookies whose names start with "site"
My code is as follows.
var all_cookies = $.cookies.filter( /^mark/ );
$('aside').html(''+all_cookies+'');
When I execute the above code though, the inner HTML of aside
is [object Object]
. What am I doing wrong?
I'm using external library, jquery.cookies.2.2.0.min.js
, and according to the documentation you get a list of all cookies like so.
jaaulde.utils.cookies.filter( /^site/ );
returns list of cookies whose names start with "site"
My code is as follows.
var all_cookies = $.cookies.filter( /^mark/ );
$('aside').html(''+all_cookies+'');
When I execute the above code though, the inner HTML of aside
is [object Object]
. What am I doing wrong?
- Might be useful to note that this is an external library. – user672118 Commented May 15, 2012 at 0:17
1 Answer
Reset to default 8This is because Jaaulde returns an object where the key is the name of the cookie and the value is the value of the cookie. So Jaaulde is returning something like this.
{ site_one: 'one',
site_two: 'two' }
You can't convert an object to a string like that. You need to iterate through each key-value pair and append those individually. Which can be done like so.
$.each(all_cookies, function(key, value) {
$('aside').append('Key: ' + key + '; Value: ' + value);
});
本文标签: javascriptHow to get a list of cookies with jQueryStack Overflow
版权声明:本文标题:javascript - How to get a list of cookies with jQuery? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745378643a2656055.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论