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?

Share Improve this question edited May 15, 2012 at 7:53 Teq1 asked May 15, 2012 at 0:14 Teq1Teq1 6311 gold badge7 silver badges20 bronze badges 1
  • Might be useful to note that this is an external library. – user672118 Commented May 15, 2012 at 0:17
Add a ment  | 

1 Answer 1

Reset to default 8

This 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