Need help with using session.setItem and session.getItem

This may be trivial, but I have spent 2 days trying various options to pass a parameter from one page to another. Of course, it hasn’t worked or I wouldn’t be here.

Help would be greatly appreciated!

Below is my code and log results:

Page 1


import { session } from ‘wix-storage’ ;

$w . onReady ( function () {

$w ( ‘#button1’ ). onClick (( event ) => {
session . setItem ( “stage” , “1” );
console . log ( 'Stage selected is ’ + session . getItem ( “stage” ) );
});

$w ( ‘#button2’ ). onClick (( event ) => {
session . setItem ( “stage” , “2” );
console . log ( 'Stage selected is ’ + session . getItem ( “stage” ) );
});

$w ( ‘#button3’ ). onClick (( event ) => {
session . setItem ( “stage” , “3” );
console . log ( 'Stage selected is ’ + session . getItem ( “stage” ) );
});

$w ( ‘#button4’ ). onClick (( event ) => {
session . setItem ( “stage” , “4” );
console . log ( 'Stage selected is ’ + session . getItem ( “stage” ) );
});

$w ( ‘#button5’ ). onClick (( event ) => {
session . setItem ( “stage” , “5” );
console . log ( 'Stage selected is ’ + session . getItem ( “stage” ) );
});

});

Page 2


import { session } from ‘wix-storage’ ;

$w . onReady ( function () {
session . getItem ( “stage” );
console . log ( 'Stage received is ’ + session . getItem ( “stage” ) );

});

Logs


Running the code for the Stage Selection for Stage Variables page. To debug this code in your browser’s dev tools, open zqgnc.js.

Stage selected is 1

Stage Selection for Stage Variables
Line 13

Running the code for the Stage Variables page. To debug this code in your browser’s dev tools, open hxphl.js.

Stage received is 5

Stage Variables
Line 11

Running the code for the Stage Selection for Stage Variables page. To debug this code in your browser’s dev tools, open zqgnc.js.

Stage selected is 2

Stage Selection for Stage Variables
Line 18

Running the code for the Stage Variables page. To debug this code in your browser’s dev tools, open hxphl.js.

Stage received is 1

Stage Variables
Line 11

Running the code for the Stage Selection for Stage Variables page. To debug this code in your browser’s dev tools, open zqgnc.js.

Stage selected is 3

Stage Selection for Stage Variables
Line 23

Running the code for the Stage Variables page. To debug this code in your browser’s dev tools, open hxphl.js.

Stage received is 2

Stage Variables
Line 11

Running the code for the Stage Selection for Stage Variables page. To debug this code in your browser’s dev tools, open zqgnc.js.

Stage selected is 4

Stage Selection for Stage Variables
Line 28

Running the code for the Stage Variables page. To debug this code in your browser’s dev tools, open hxphl.js.

Stage received is 3

Stage Variables
Line 11

Running the code for the Stage Selection for Stage Variables page. To debug this code in your browser’s dev tools, open zqgnc.js.

Stage selected is 5

Stage Selection for Stage Variables
Line 33

Running the code for the Stage Variables page. To debug this code in your browser’s dev tools, open hxphl.js.

Stage received is 4

Help would be greatly appreciated. I see views going up, but no help yet.

Thanks!

Maybe because you are an unknowm member?
There are a lot of UKNOWM-MEMBER here just hunting for some free-codes, to avoid payed coders.

Maybe you first become a → KNOWN-MEMBER?

I am a member!!! Now, would you please help me.

I am a member! Now would you please help me.

You are talking about that something do not work.
What exactly do not work ?

Please review information supplied. I am trying to pass a parameter from page to page 2 using session.setiTem and session.getItem. As you can see from the console logs provided, the selected value does not equal the received value.

Pretty simple, just not working.

Thanks for your time and support!

The unknown member showing is a forum issue. If you see blank avatars with “unknown member”, you may have to refresh. I have made the forum team aware that this happens sometimes.

Regarding your code, everything looks just well.
Testing your code —> also works like a charm!

Just a simple testing page…

https://russian-dima.wixsite.com/my-site-4/blank-6

Page-1 (sendind…)

import wixlocation from 'wix-location'
import {session} from 'wix-storage';


$w.onReady(()=> {   
    $w('#button1').onClick((event) => {    
        session.setItem("stage", "1");
        console.log('Stage selected is ' + session.getItem("stage") );
        wixlocation.to("https://russian-dima.wixsite.com/my-site-4/reciever-site");
    });   

    $w('#button2').onClick((event) => {
        session.setItem("stage", "2");
        console.log('Stage selected is ' + session.getItem("stage") );
        wixlocation.to("https://russian-dima.wixsite.com/my-site-4/reciever-site");
    });   

    $w('#button3').onClick((event) => {
        session.setItem("stage", "3");
        console.log('Stage selected is ' + session.getItem("stage") );
        wixlocation.to("https://russian-dima.wixsite.com/my-site-4/reciever-site");
    });   

    $w('#button4').onClick((event) => {
        session.setItem("stage", "4");
        console.log('Stage selected is ' + session.getItem("stage") );
        wixlocation.to("https://russian-dima.wixsite.com/my-site-4/reciever-site");
    }); 

    $w('#button5').onClick((event) => {
        session.setItem("stage", "5");
        console.log('Stage selected is ' + session.getItem("stage") );
        wixlocation.to("https://russian-dima.wixsite.com/my-site-4/reciever-site");
    });  
});

Page-2…(receiving):

import {session} from 'wix-storage';

$w.onReady(()=> {    
    session.getItem("stage");
    console.log('Stage received is ' + session.getItem("stage"));
});

Do the test and take a look at console.

If the code is good, why did my log show stage selected and stage received were different almost every run? The best I can tell is that it was some kind of a timing issue using my stage site. Once I out a timeOut in on my receiving page, it began working for me. I never thought storing data using “session” would be impacted by timing, but it was. Does that make sense to you?

Thanks for your time and support! I appreciated the help.

Sincerely,
Doug Milligan