mirror of
https://github.com/localForage/localForage.git
synced 2026-01-18 14:31:57 +00:00
The console log was showing the error value instead of the value of the key being looked up!
35 lines
1.0 KiB
HTML
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>
|