www.webdeveloper.com
Results 1 to 2 of 2

Thread: Using JSON in SessionStorage

  1. #1
    Join Date
    Mar 2013
    Posts
    1

    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:
    Code:
    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);
    		window.location.href='Home.html';
    and in the page that the display of the array should be i wrote:

    Code:
    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>";
    		$("#main_section").append(newArticle);
    	}
    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
    Location
    urbana, il
    Posts
    2,787
    you are only saving one article, but your loader is trying to loop through many of them.

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



Recent Articles