Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Digisol's avatar

GET Method not supported on route, but I am using POST

I am sending a POST request via AJAX to a route called store_fr. Any time I fire the call I am getting an error that the route does not support the GET method (I am sending the call as post).

Ajax call:

        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });
        $.ajax({
            type: 'POST',
            url: "{{ route('ajax.store_fr') }}",
            data: {
                id: $('#list').val(),
                official_title_fr: $('#official_title_fr').val(),
            },

            success: function(data) {

                $.ajax({
                    type: 'GET',
                    url: "{{ route('pdf') }}",
                    data: {
                        id: $('#countryList').val(),
                    },

                    success: function(data) {

                        downloadHTML(html_data.success['id'], html_data.success['name'],
                            'en');

                        downloadHTML(html_data.success['id'], html_data.success['name'],
                            'fr');

                        $('#loading').hide();

                        Swal.close();

                        Swal.fire({
                            icon: 'success',
                            returnFocus: false,
                            onAfterClose: () => window.scrollTo(0, 0)
                        });


                    },
                    error: function() {
                        Swal.close();

                        Swal.fire({
                            icon: 'error',
                            returnFocus: false,
                            onAfterClose: () => window.scrollTo(0, 0)
                        });

                        $('#loading').hide();

                    }
                });
            }
        });

My routes:

Route::controller(AjaxController::class)->group(function () {
    Route::get('/ajaxretrieve', 'index')->name('ajax.retrieve');
    Route::post('/ajaxstore', 'store')->name('ajax.store');
    Route::post('/ajaxstorefr', 'store_fr')->name('ajax.store_fr');
});

and the body of the error code:



        $this->methodNotAllowed($methods, $request->method());

    }



    /**

     * Throw a method not allowed HTTP exception.

     *

     * @param  array  $others

     * @param  string  $method

     * @return void

     *

     * @throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException

     */

    protected function methodNotAllowed(array $others, $method)

    {

        throw new MethodNotAllowedHttpException(

            $others,

            sprintf(

                'The %s method is not supported for this route. Supported methods: %s.',

                $method,

                implode(', ', $others)

            )

        );

    }



    /**

     * Compile the routes for caching.

     *

     * @return array

     */
0 likes
6 replies
tykus's avatar
tykus
Best Answer
Level 104

Are you clicking on a link to trick reaction and have you prevented the default behaviour?

Digisol's avatar

@tykus Yes, I'm clicking on a button and have prevented the default behavior.

Digisol's avatar

@tykus I've figured out that it isn't actually the method, that error is only springing up once I click on the route in the console, so I just have to debug the internal code.

deansatch's avatar

are you sure the error isn't regarding your 'pdf' route? That one is a GET request

Digisol's avatar

@deansatch Yes, the console log states that the error is hitting on the store_fr route.

Please or to participate in this conversation.