getItem() returning NULL value

I found out about setItem() and getItem() as my solution to save value that can be used in another page, but I am getting NULL in 2nd page, here is the code in Page 1

import {local} from ‘wix-storage’ ;
export function box8_click(event,$w) {
local.setItem( “jsundertf” , “T-Shirt” );
}

Code in Page 2

import {local} from ‘wix-storage’ ;

export function button1_click(event,$w) { \
let x= local.getItem( “jsundertf” ) ;
console.log(x)
}

Returns NULL

I have tried with session and memory, but the result is still the same.

I want to create a value using setItem() in one page and retrieve the same value in another page using getItem(). Please help, I am very new in this programing and web development. I am stuck badly. Thanks in advance

Normaly your generated CODE should work.

But anyway, try this way…

Main-Page-Code:

import {local} from 'wix-storage';
import wixLocation from 'wix-location';

$w.onReady(function () {
  $w('#button1').onClick(()=>{
      local.setItem("key1", "T-Shirt"); 
      wixLocation.to("insertHereTheUrlOfTheSecondSite")//Navigation to second site
  });
});

Sub-Page-Code:

import {local} from 'wix-storage';

$w.onReady(function () {
    $w('#button1').onClick(()=>{
 let x =local.getItem("key1"); 
        console.log(x) 
    });
});

Good luck.

You are a genius. Thank you so much. But why is it not redirecting to the page link given? Please help.

Thanks for information

@theastylesie
Did you change → "insert HereTheUrlOfTheSecondSite " to your own link
Do you use dynamic pages?

Please take a look onto this API:
https://www.wix.com/velo/reference/wix-location
…especialy this one…
https://www.wix.com/velo/reference/wix-location/to

@russian-dima Wonderful. It is working now. Thanks a trillion.

@theastylesie
No problem. :wink:

Hi, I’m having the same issue, but in my case I’m trying to pass 2 values instead of 1.

When i console.log the page it shows me only 1 value passed and not the other. what might be causing that ? how can i fix it?

To pass 2-values instead of just one you could do it like that…

Main-page:

import {local} from 'wix-storage';

$w.onReady(function () {
  $w('#button1').onClick(()=>{
      local.setItem("key1", "T-Shirt"); 
      local.setItem("key2", "Jacket"); 
      wixLocation.to("insertHereTheUrlOfTheSecondSite")//Navigation to second site
  });
});

Sub-page:

import {local} from 'wix-storage';

$w.onReady(function () {
    $w('#button1').onClick(()=>{
        let x =local.getItem("key1"); 
        let y =local.getItem("key2"); 
        console.log(x), console.log(y)
    });
});