How to pass data from ajax to laravel 5.2 controller via post method
<p>Hello StackOverflow family. This is my very first question and I hope to get help.</p>

<p>I'm new to laravel framework and am using version 5.2 in my project.
Am trying to pass data using the post method from my ajax function to a particular controller method but no data is passed to the controller. </p>

<p>I followed the steps in this forum <a href="https://laracasts.com/discuss/channels/laravel/process-data-in-controller-using-ajax-in-laravel" rel="nofollow noreferrer">https://laracasts.com/discuss/channels/laravel/process-data-in-controller-using-ajax-in-laravel</a> but can't get it to work. Here is what I've done so far.</p>

<p>My JavaScript (<code>post_script.js</code>):</p>

<pre><code>$.ajax({
    method: 'POST',
    url: './home',
    data: {
        userID: 76,
        userName: 'Jimmy'
     },
});
</code></pre>

<p>Note that this file is saved in <code>assets/js</code> directory in the laravel structure. Here is what I have in my route file (<code>routes.php</code>):</p>

<pre><code>Route::get('/', "MyController@home");
Route::get('home', "MyController@home");
</code></pre>

<p>Here is the function I have in <code>MyController.php</code> file:</p>

<pre><code>function home(Request $request) {
    $userID = $request['userID'];
    $userName = $request['userName'];
    return view('home', [
      'userID'=&gt; $userID,
      'userName' =&gt; $userName
    ]);
}
</code></pre>

<p>In my view, I tried to access it like this:</p>

<pre><code>&lt;p&gt;User ID: {{$userID}}&lt;/p&gt;
&lt;p&gt;User Name: {{$username}}&lt;/p&gt;
</code></pre>

<p>Nothing is displayed! Please what am I doing wrong? I need your help. Forgive me if my question is not proper but I hope you get what I mean. Thank you</p>