Hello StackOverflow Family This is my first question, and I hope to get help.
I am new to the laravel framework and am using version 5.2 in my project. I am trying to pass data using the post method from my ajax function to a specific controller method, but the data is not being transferred to the controller.
I followed the steps in this forum https://laracasts.com/discuss/channels/laravel/process-data-in-controller-using-ajax-in-laravel , but could not get it to work. Here is what I have done so far.
My JavaScript ( post_script.js):
$.ajax({
method: 'POST',
url: './home',
data: {
userID: 76,
userName: 'Jimmy'
},
});
Note that this file is stored in a directory assets/jsin the laravel structure. Here is what I have in the route ( routes.php) file :
Route::get('/', "MyController@home");
Route::get('home', "MyController@home");
, MyController.php:
function home(Request $request) {
$userID = $request['userID'];
$userName = $request['userName'];
return view('home', [
'userID'=> $userID,
'userName' => $userName
]);
}
, :
<p>User ID: {{$userID}}</p>
<p>User Name: {{$username}}</p>
! , ? . , , , , .