Reputation: 88
I have a Symfony application. I am saving some information on the session in it, using request->getSession()->set(key, value)
.
If I call an action via a client side AJAX call, I can't access the session variables, which I saved earlier. It looks like the AJAX call generates me a completely new session (new session id, compared to the one present in the main flow).
I have the following settings in config.yml
:
session:
cookie_lifetime: 3600
cookie_httponly: false
The strange thing is, that on localhost I get the same sessionId via AJAX (so on localhost everything works fine). The issue started to appear after I deployed it on a webserver.
Please advise. Thanks
Upvotes: 2
Views: 1736
Reputation: 3085
If you call an action from the controller via Ajax? In which you mean a server-side Ajax call? That's a bit weird. Let's say you would do that, the server does not have the same session but it will create a new session that is not related to the user its session.
Think you should use the Controller its forward
method. See http://symfony.com/doc/current/book/controller.html#forwarding-to-another-controller
Or move the method you'd like to call to it's own class and configure a service for that: http://symfony.com/doc/current/components/dependency_injection/configurators.html
Upvotes: 1