Make an Ajax call to plug-in controller I am trying to send data to my plug-in controller using jquery $.post() method.
here is my form:

&lt;form method="post" action="" accept-charset="UTF-8" id="testForm"&gt;
  {{ csrfInput() }}
  &lt;input type="hidden" name="action" value="test/test"&gt;
  &lt;button type="submit"&gt;Test&lt;/button&gt;
&lt;/form&gt;


and this is my js code:

&lt;script type="text/javascript"&gt;
   window.csrfTokenName = "{{ craft.config.csrfTokenName|e('js') }}";
   window.csrfTokenValue = "{{ craft.request.csrfToken|e('js') }}";
&lt;/script&gt;
&lt;script&gt;
$("#testForm").submit(function (e) {
    e.preventDefault();
    var data = [];
    data["test"] = "test";
    data[csrfTokenName] = csrfTokenValue;
    $.post('/', data, function(response) {
        console.log(response);
    });
});
&lt;/script&gt;


The console keeps logging "400 Bad Request".
What am I doing wrong ?
You need to define a route via action param otherwise Craft has no idea where to route the request. Your data variable only only contains

data = [
    'test' =&gt; 'test',
    TOKEN_NAME =&gt; TOKEN_VALUE
]


and nothing else

You need to include action =&gt; plugin-handle/controller-id/function-name

You can see a working example at basic ajax how to