I’m creating a website that needs to be able to send data between different pages, and as far as I understand I need to use Wix-storage to do that. so I used session storage but whatever value I set In the session storage I get a null when I try to read it. am I doing something wrong?
setting the value:
session . setItem ( “space” , “roof” );
reading the value:
console . log ( session . getItem ( “space” ));
thanks in advance
Hi there,
You should know that although this seems instantaneous, it’s actually not, try to introduce a slight delay between saving into the storage and reading from it.
session.setItem('space', 'roof');
setTimeout(() => {
const item = session.getItem('space');
console.log(item);
}, 250)
That seemed to do it, thanks!
Hey there.
I’ve been having the same problem as described above.
It seems timeout isn’t the issue in my case, since I read the information immediately and it reads it fine, but later on in the session I get null.
My code is (simplified):
// Lightbox code
export function button15_click(event) {
session.setItem("code", $w("#input1").value);
console.log(session.getItem("code")); // Shows the correct input
wixWindow.lightbox.close();
}
// HomePage code - triggered when scrolling to bottom of the page after a few seconds
let code = session.getItem("code");
console.log(code); // Shows null
Hey there,
Can you share the full code, I can’t see the full picture from this snippet.
I eventually used:
wixWindow.openLighbox("lighbox").then((data) =>
{
let code = data;
}
instead, so I don’t need the session.getItem(), but there’s definitely improper behavior with the session feature there for you to examine.
The full homepage code was:
import {session} from 'wix-storage';
$w.onReady() {
wixWindow.openLightbox("lightbox");
let code = session.getItem("code");
console.log(code); // Shows null
}
where the lightbox code was:
import {session} from 'wix-storage';
export function onclick_button1(event) {
session.setItem("code", $w("#input1").value);
console.log(session.getItem("code")); // Shows the correct input
wixWindow.lightbox.close();
}
The value in the #input1 box was displayed properly in the Lighbox’s code, but in the homepage’s code the output was null.