如何在Symfony 3中获取ajax请求的post参数

I have an ajax request working fine. My problem is I do not really know how to use correctly my controller to get the datas in the format I would like.

I would like to use this kind of method:

$request->request->get('pseudo'); // will return "bob"

Here is my controller code:

public function mainPlayAction(Request $request)
{

    if ($request->isXmlHttpRequest())
    {
        $allContent = $request->getContent(); // will return a string with this format "selectedBalls=34&selectedStars=11"

        $selectedBalls = $request->request->get('selectedBalls'); // will return null

        $selectedstars= $request->request->get('selectedStars'); // will return null

        $all = $request->request->all(); // will return Array[0]

        $response = [
            'allContent' => $allContent,
            'selectedballs' => $selectedBalls,
            'selectedStars' => $selectedStars,
            'all' => $all,                
            'success' => true,
            "status" => 100
        ];

        return $this->json($response);
    }
}

Here is my ajax code

$.ajax({
    url: url,
    dataType: "json",
    contentType: "application/json; charset=utf-8",
    type: "POST",
    data: {
        'selectedballs': selectedBalls,
        'selectedStars': selectedStars,
        'countGames': countGames
    },
    success: function (response) {
        window.console.log(response);
    },
})

You simply need to call ->get() on Request object to get the data passwed along with AJAX Request.

Like this,

$selectedballs=$request->get('selectedballs');
$selectedStars=$request->get('selectedStars');
$countGames=$request->get('countGames');

I found a good answer.

I deleted this line of code from my ajax request

contentType: "application/json; charset=utf-8"

And now I can retrieve my datas using

$request->get('selectedBalls');