Why jQuery.cookie returns “[object Object]” for a single string value

后端 未结 5 1468
故里飘歌
故里飘歌 2021-01-26 11:40

I set a cookie on Rails like this,

cookies[:account] = { :value => @account.to_s, :expires => 3.month.from_now }

Which seems to be workin

5条回答
  •  再見小時候
    2021-01-26 12:14

    [object Object] is the return value from Object.toString(), so that means that $.cookie('account') is returning a non-Number, non-String object.

    On way to start figuring out what's in the return value (in an effort to help you determine what's in the object returned) is to loop over the properties to figure it out.

    So, like this:

    var obj = $.cookie('account');
    var msg = [];
    for(var i in obj)  msg.push( i +" = " + obj[i]);
    alert(msg.join("\n")); // or console.log(msg.join("\n"));
    

提交回复
热议问题