Store in session value from ajax post request

Hello everyone,

i don’t understand if this i doable, i’m trying to create an ajax request to pass some data to a controller and than store it in session.

JS:


/*

 * Get data from localhost server

*/

function getGSData() {

    return $.ajax({

        type: "get",

        dataType: 'json',

        url: "http://localhost",

        crossDomain: true,

    });

}


/*

 * Send data to framework

*/

function sendGSData() {

    getGSData()

    .done(function(gsdata) {

        console.log(JSON.stringify(gsdata));

        $.ajax({

            type: "post",

            url: "actionURL",

            data: { gsdata: gsdata },

        }).done(function(data){console.log(JSON.stringify(data));});

        

    });

}

CONTROLLER


    

public function actionGsdata()

    {

        if (Yii::$app->request->isAjax && Yii::$app->request->getIsPost()) {

            $gsdata = Yii::$app->request->post();

            Yii::$app->session['gsdata'] = $gsdata;

        }

    }



from console i can see the value with console.log(JSON.stringify(gsdata)); but no variable is stored.

Is it possible to do that or i’m just doing something wrong?

Thanks.

Ok, i solved it… i did just need to refresh the page in order to populate the session variable ::)