javascript - How to get a list of cookies with jQuery? - Stack Overflow

I'm using external library, jquery.cookies.2.2.0.min.js, and according to the documentation you ge

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);
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745378643a4625119.html

相关推荐

  • javascript - How to get a list of cookies with jQuery? - Stack Overflow

    I'm using external library, jquery.cookies.2.2.0.min.js, and according to the documentation you ge

    6小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信