localForage/examples/index.html
Rob Evans f4893cc582 Fixed bug in call to getItem using first argument as return value instead of second
The console log was showing the error value instead of the value of the key being looked up!
2014-11-14 11:03:15 +00:00

35 lines
1.0 KiB
HTML

<!doctype html>
<html>
<head>
<meta charset="utf8" />
<title>Simple localForage example</title>
</head>
<body>
<script src="../dist/localforage.js"></script>
<script>
// Forcing localstorage here. Feel free to switch to other drivers :)
localforage.setDriver(localforage.LOCALSTORAGE).then(function() {
var key = 'STORE_KEY';
// var value = 'What we save offline';
var value = new Uint8Array(8);
value[0] = 65
// var value = undefined;
var UNKNOWN_KEY = 'unknown_key';
localforage.setItem(key, value, function() {
console.log('Saved: ' + value);
localforage.getItem(key, function(err, readValue) {
console.log('Read: ', readValue);
});
// Since this key hasn't been set yet, we'll get a null value
localforage.getItem(UNKNOWN_KEY, function(err, readValue) {
console.log('Result of reading ' + UNKNOWN_KEY, readValue);
});
});
});
</script>
</body>
</html>