Results 1 to 2 of 2

Thread: Using JSON in SessionStorage

  1. #1
    Join Date
    Mar 2013

    Using JSON in SessionStorage

    hey, so ive been trying to create an array of newly created articles and save it on the session.
    on the article creating form i did something like that:
    var createdArticles = new Array();
    		createdArticles[0] = $("#title").val();
    		createdArticles[1] = $("#subtitle").val();
    		createdArticles[2] = $("#content").val();
    		createdArticles[3] = $("#name").val();
    		var jsData = JSON.stringify(createdArticles);
    		sessionStorage.setItem("allData" , jsData);
    and in the page that the display of the array should be i wrote:

    var createdArticles = new Array();
    	var jsCreatedArticles = sessionStorage.getItem("allData");
    	var createdArticles = JSON.parse(jsCreatedArticles);
    	for (var i=0; i < createdArticles.length , i++)
    		var newArticle = "<article><header><hgroup><h1> " + createdArticles[0]+ "</h1><h2> " + createdArticles[1] + "</h2></hgroup></header><p> " + createdArticles[2] + "</p><footer><p> -Written by " + createdArticles[3] + "</p></footer></article>";
    its not working for me, im using ref to json_parse.js and to json2.js.

    any ideas? thanks

  2. #2
    Join Date
    Jul 2008
    urbana, il
    you are only saving one article, but your loader is trying to loop through many of them.
    Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center