Symfony3: Set Session Attribute with AJAX
<p>I'm using Symfony 3.1 and I try set a session attribute with AJAX. I saved something in the session before in a controller. Now I created a new controller for the AJAX request that looks like this:</p>

<p><strong>AjaxController.php</strong></p>

<pre><code>namespace AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;


class AjaxController extends Controller {

    /**
     * @Route("/addId/{id}", name="addId")
     */
    public function hideCookieMessageAction(Request $request, $id) {

        $session = $request-&gt;getSession();
        $session-&gt;set('id', $id);

        $response = new Response();
        return $response;

    }

}
</code></pre>

<p><strong>ajax.js</strong></p>

<pre><code>$(document).ready(function() {

    $('.addIdButton').click(function {

        var id = 1;

        $.ajax({
            type: 'POST',
            url: 'addId/' + id,
            async: false,
        })
        .fail(function() {
            alert('Couldn\'t add flat to wishlist');
        });

    });

});
</code></pre>

<p>I don't get any AJAX or JS error message. But if I look into the Symfony Profiler there is no new Session Attribute. I tried it with a cookie too and it worked. So I think it has nothing to do with a wrong AJAX call but with a wrong session handling in the controller. </p>

<p>Does someone has an idea?</p>