H
H
Hermes2022-02-11 17:38:14
Yii
Hermes, 2022-02-11 17:38:14

How to get cookie value on ajax request in Yii2?

I'm trying to get a cookie with:

Yii::$app->request->cookies->get(Partner::TRACK_TAG)->value


When I do this in a test action , I get the correct value:
2

The test action itself:
public function actionCookie()
    public function actionCookie()
    {
        var_dump(Yii::$app->request->cookies->get(Partner::TRACK_TAG)->value);
        die;
    }


When receiving occurs as part of an AJAX request , I get the encoded value:
6b8dac707515065fcc82a1ba3d9f8f4937bd2bffd5e3741be410e80ef7824924a:2:{i:0;s:1:"p";i:1;s:1:"2";}


I tried to put the CSRF token into the form (there is one in the meta tags) to check if it helps - it didn't help:
<input type="hidden" name="_csrf-frontend" value="<?= Yii::$app->request->csrfToken ?>">

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question