4

I have a phonegap application that communicates with a server using ajax and cookies for session managment.

I need to access the cookies in the client side. I've tried:

document.cookie;

However, this results in an empty string.

I know that the cookies are set, because the server that the client communicates with can see them.

At first I thought that it is empty because I access document.cookie from a different js file, but even from the same file that makes the ajax request I get an empty string.

Through Chrome's Resources->cookies->localhost I see that the cookies actually exist.

I checked over the server whether the HttpOnly flag is set to true, but it isn't.

Any ideas?

Thanks!

Edit:

I found this plugin:
https://github.com/carhartl/jquery-cookie

However, this results in an empty string as well.

Niv
  • 2,294
  • 5
  • 29
  • 41

2 Answers2

2

On Phonegap document.cookie is empty, since index.html and all other files are loaded with file:// protocol.

You must use localStorage.

Gottlieb Notschnabel
  • 9,408
  • 18
  • 74
  • 116
Ferro
  • 21
  • 2
1

You might want to have a look at the plugin http://plugreg.com/plugin/bez4pieci/Phonegap-Cookies-Plugin

Git: https://github.com/bez4pieci/Phonegap-Cookies-Plugin

Vinoth
  • 657
  • 6
  • 12