problem in passing Data ajaxly I want to do some tasks with ajax in drupal, in client side I passed data with 

                jQuery.ajax({
                    url: '/rest/session/token',
                    method: 'GET',
                    success: function (token, status, xhr) {
                        var postData = {}
                        postData= {'name': 'user','pass': 'pass'};
                        jQuery.ajax({
                            url: "/mylogin",
                            method: "POST",
                            data: postData,
                            dataType: "json",
                            headers: {"Accept": "application/json", "X-CSRF-Token": token, "Content-Type": "application/json"},
                            success: function (data, status, xhr) {
                                console.log(data);
                            }
                        });
                    }
                });


and  ccording How to get $_POST parameters in my controller I try to catch posted data with 

public function login(){
    //return new JsonResponse( \Drupal::request()-&gt;request-&gt;all()); // form param);
    return new JsonResponse( \Drupal::request()-&gt;request-&gt;get('name')); // form param);
}


I reutrn empty, ( JsonResponse work correctly, I test it with example data ).

what is the problem and why I can't get Posted data in my controller's method?
If you're POSTing a JSON string, it won't be available as key/value pairs in Symfony's request object.

You could parse it yourself:

$json_string = \Drupal::request()-&gt;getContent();
$decoded = \Drupal\Component\Serialization\Json::decode($json_string);
$name = $decoded['name'];