用ajax设置cookie

I know this topic was discussed several times. But I can't really figure out why my example is not working.

I have tested it locally and it works.

localhost-cookie-storing
As you can see there are some received cookies.

But on the real web site it is not working. The code is exactly the same.
enter image description here
As you can see there are only sent cookies.

JS and PHP sides are very simple. This is for sure not the coding problem.
This is for example server side (Yii2 PHP framework)

$cookie = new Cookie(); $cookie->name = 'agree-terms'; $cookie->value = '1'; $cookie->expire = time() + 2592000; Yii::$app->getResponse()->getCookies()->add($cookie); echo Json::encode(['success' => true]);

May be something wrong with requests or can be the server configuration. It appears on cargo2share.com website while clicking on close button of cookie agreements block on the bottom of the page.

Any hints are appreciated.

EDIT comparing the response headers:

localhost:

enter image description here


and live version

enter image description here