Support the ongoing development of Laravel.io →
Requests Laravel

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?

Last updated 2 years ago.
0

You can see bellow link for ajax POST request with Laravel 6 : https://www.itsolutionstuff.com/post/laravel-6-ajax-request-exampleexample.html

Last updated 5 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.