This is my ajax function in the view that should be called when a select change the selected option (onchange):
function fillEmployeeData(emp_id) {
var emp_selected = emp_id.value;
$.ajax({
type: "POST",
url: "{{ route('adminAreaPostEmployee') }}",
data: 'emp_selected=' + emp_selected,
success: function(data){
var emp_data = JSON.parse(data);
alert(emp_data);
}
});
};
This is my route:
Route::post('/adminarea/postemployee', 'AdminAreaController@post_employee')->name('adminAreaPostEmployee');
And this is my controller function:
public function post_employee(Request $request)
{
$select = $request -> get ('emp_selected');
$user = User::where('id', $select);
echo $user;
}
But for some reason I receive this error and I don't see the alert:
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException The GET method is not supported for this route. Supported methods: POST.
Do you have any idea about the problem?
You can see bellow link for ajax POST request with Laravel 6 : https://www.itsolutionstuff.com/post/laravel-6-ajax-request-exampleexample.html
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community