0

I'm using the plugin jQuery.cookie by carhartl on my phonegap build project. However when I try to create a cookie and then read it, it return a null value : [object Object].

Here is the code :

$(".validator").click(function(){

    $.ajax({
        type: "POST",
        url: "http://path/to/adduser.php",
        data: dataString,
        cache: false,
        success: function(result){

        $.cookie('name', 'yolo', { path: '/' });
        alert($.cookie()); 
    });
 }); 

Do you have any idea to help me resolve my problem ?

casusbelli
  • 463
  • 1
  • 5
  • 22

3 Answers3

3

You need to provide the cookie name to read it:

alert($.cookie('name'));
Barmar
  • 741,623
  • 53
  • 500
  • 612
1

The readme file, available in the git repository linked in the question, shows that the cookie() method returns an object:

$.cookie(); // => { "name": "value" }

The alert() method doesn't know anything about what the object contains, which is why it is displaying [object Object]. You need to instead use $.cookie('name') to point to the specific value stored inside the object.

Sam
  • 8,330
  • 2
  • 26
  • 51
0

I found out.

It is because I use google chrome to test my app which ignore local jQuery cookies.

Thanks.

Cf

why-are-all-my-jquery-cookies-turning-up-undefined

why-does-chrome-ignore-local-jquery-cookies

Community
  • 1
  • 1
casusbelli
  • 463
  • 1
  • 5
  • 22