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);
});
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745378643a4625119.html
评论列表(0条)