Writing/reading objects in cookies


So I need to make a webshop for a school project.
I wrote the javascript for my shopping cart page.

I made an object Artikel and an object ArtikelList which contains an array of Artikel objects. Then I save the ArtikelList object into a cookie.
But when I try to read the data from the cookie again I can’t get it to work.

Let me know if you need more info/details…

Could someone please point out any mistakes that could solve my problem?


Links with the javascript:
[JavaScript] artikelToevoegenAanWinkelkarretje.js - Pastebin.com
[JavaScript] winkelkarretjeInlezen.js - Pastebin.com

Have you checked that the cookie is actually being written?

In any case your cookie reader should return a string not type object, which is what your notes suggest you’re getting.
You could try the function below instead.

Remember that the value returned is still a string until converted using JSON.parse();

function getCookie( naam ) 
  var cookieArray = document.cookie.split( /;\\s*/ ),
      cValue = ""; 
  for( var teller = 0; teller < cookieArray.length && !cValue; teller++ ) 
    if( ( cookie = cookieArray[ teller ] ).indexOf( naam ) == 0 ) 
      cValue = cookie.split( "=" )[ 1 ]; 
  return decodeURIComponent( cValue );