7

So I think jStorage is what I need to solve one of my problems. It needs JSON to be working with jQuery, so I've tried including it, but it doesn't seem to work. I have no idea what JSON is actually. Here's my code (jQuery is loaded higher). It doesn't even show the alert window.

<script type="text/javascript" src="jquery.json-2.2.min.js"></script>
<script type="text/javascript" src="jstorage.js"></script>
<script type="text/javascript">
$.jStorage.set(key, 'test');  
value = $.jStorage.get(key);
alert("test"+value);
</script>

What could cause this?

2 Answers2

10
$.jStorage.set('key', 'test');  
value = $.jStorage.get('key');
alert("test"+value);

See http://www.jstorage.info/#usage: key needs to be string otherwise an exception is thrown

bogdan
  • 671
  • 5
  • 16
2

As i just discovered, the key/value set can be literally just about anything:

$.jStorage.set('matrix_nums', {"matrix":"$55\/HR","matnum":"25"},{"matrix":"225-17-01","matnum":"157"},{"matrix":"225-1708","matnum":"134"},{"matrix":"225-2708","matnum":"129"});

var _matrix = $.jStorage.get('matrix_num');
//test var for value
if(_matrix) {
    $.each( _matrix, function(k,v) {
       //... do stuff
} else {

load your JSON string manually and save it into local storage.

Kijewski
  • 25,517
  • 12
  • 101
  • 143
geekbuntu
  • 851
  • 6
  • 4