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

whoisthisstud's avatar

Stupid Ajax POST not allowed issue.. ARGH!

Ok. I'm about to lose my mind. I'm sure I'm missing something simple and just can't see the forest from the trees, but I'm getting the following error when I attempt to submit this form through ajax:

The POST method is not supported for this route. Supported methods: GET, HEAD.

FORM

<head>
    <!-- CSRF Token -->
    <meta name="csrf-token" content="{{ csrf_token() }}">
</head>

[...]

<form id="businessRequestForm" method="POST">
    @csrf
    <div class="form-group">
        <select class="custom-select mr-sm-2" id="city_id" name="city_id">
            <option selected>Choose City...</option>

            @foreach( $select_states as $state )
                @if( $state->cities->count() > 0 )
                    <optgroup label="{{ $state->name }}">
                        @foreach( $select_cities as $city )
                            @if( $city->state_id === $state->id )
                                <option value="{{ $city->id }}">{{ $city->name }}</option>
                            @endif
                        @endforeach
                    </optgroup>
                @endif
            @endforeach

        </select>
        <small id="cityError" class="form-text text-muted"></small>
    </div>
    <div class="form-group">
        <label for="exampleInputEmail1">Business Name</label>
        <input type="text" class="form-control" id="business" name="business" aria-describedby="business">
        <small id="businessNameError" class="form-text text-muted"></small>
    </div>

    <div class="form-group pt-3">
        <button type="submit" class="btn btn-primary btn-block">
            Submit Business Request
        </button>
    </div>

</form>

AJAX

<script>
$.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});
$('#businessRequestForm').on('submit', function (e) {
    e.preventDefault();
    var cityID = $('#city_id').val();
    var bizName = $('#business').val();

    $.ajax({
        type: 'POST',
        url: {{ route('request.business') }},
        data: {_token:token, city_id:cityID, business:bizName},
        success: function (res) {
            console.log(res); // get resposnse from controller in json
            if (res.city_idError) {
                $('#cityError').show().text(res.errorMsg);
            } else {
                $('#cityError').hide();
            }

            if (res.businessError) {
                $('#businessNameError').text(res.errorMsg);
            } else {
                $('#businessNameError').hide();
            }
        },
        error: function (data) {
            alert(data);
        }
    });
});
</script>

ROUTE

Route::post('/business-request', 'BusinessRequestController@store')->name('request.business');

REQUEST

public function authorize()
    {
        return true;
    }

    public function rules()
    {
        return [
            'city_id' => [
                'required' //,
                // new Throttle('business-request', $maxAttempts = 3, $decayInMinutes = 60)
            ],
            'business' => [
                'required', 'string', 'max:255'
            ]
        ];
    }

CONTROLLER

use App\Http\Requests\RequestBusinessRequest;

public function store(RequestBusinessRequest $request)
{
    $validated = $request->validate();

    if ($validated->fails()) {
        return response()->json(['errors'=>$validator->errors()->all()]);
    }

    // store data here

    return response()->json(['success'=>'Data is successfully added']);
}
0 likes
6 replies
jove's avatar

What about your other routes?

whoisthisstud's avatar

@jove, I'm not sure I understand your question. All of my other routes work correctly. I've even reversed the route url to '/request-business', and moved the route to the top and bottom of my routes. Same issue.

whoisthisstud's avatar

@jove, the route shows up in route:list as POST with no conflicts with any other routes.

|        | POST     | business-request                                         | request.business    | App\Http\Controllers\BusinessRequestController@store                   | web                          |
jove's avatar

@whoisthisstud Could you show the rest of the routes? Because it sounds like you have a catch all that gets used instead.

whoisthisstud's avatar

@jove, sure....

+--------+----------+----------------------------------------------------------+---------------------+------------------------------------------------------------------------+------------------------------+ 
| Domain | Method   | URI                                                      | Name                | Action                                                                 | Middleware                   | 
+--------+----------+----------------------------------------------------------+---------------------+------------------------------------------------------------------------+------------------------------+ 
|        | GET|HEAD | /                                                        | public.index        | App\Http\Controllers\PagesController@index                             | web,auth                     | 
|        | GET|HEAD | about-us                                                 | public.about        | App\Http\Controllers\PagesController@about                             | web,auth                     | 
|        | GET|HEAD | admin/business/{business}/add-discount                   | business.discount   | App\Http\Controllers\DiscountController@createBusinessDiscount         | web,auth                     | 
|        | GET|HEAD | admin/businesses                                         | businesses.index    | App\Http\Controllers\BusinessController@index                          | web,auth                     | 
|        | GET|HEAD | admin/businesses/add                                     | businesses.create   | App\Http\Controllers\BusinessController@create                         | web,auth                     | 
|        | POST     | admin/businesses/store                                   | businesses.store    | App\Http\Controllers\BusinessController@store                          | web,auth                     | 
|        | GET|HEAD | admin/businesses/{business}                              | view.business       | App\Http\Controllers\BusinessController@show                           | web,auth                     | 
|        | GET|HEAD | admin/businesses/{business}/get-logo                     | business.logo       | App\Http\Controllers\BusinessController@getLogo                        | web,auth                     | 
|        | GET|HEAD | admin/by-zip/{zip}                                       | view.zip-code       | App\Http\Controllers\CityController@showByZip                          | web,auth                     | 
|        | GET|HEAD | admin/cities/{city}/edit-city                            | cities.edit         | App\Http\Controllers\CityController@edit                               | web,auth                     | 
|        | POST     | admin/cities/{city}/update-city                          | cities.update       | App\Http\Controllers\CityController@update                             | web,auth                     | 
|        | GET|HEAD | admin/city/{city}                                        | view.city           | App\Http\Controllers\CityController@show                               | web,auth                     | 
|        | GET|HEAD | admin/city/{city}/activate                               | activate.city       | App\Http\Controllers\CityController@activate                           | web,auth                     | 
|        | GET|HEAD | admin/city/{city}/add-discount                           | city.discount       | App\Http\Controllers\DiscountController@createCityDiscount             | web,auth                     | 
|        | GET|HEAD | admin/city/{city}/deactivate                             | deactivate.city     | App\Http\Controllers\CityController@deactivate                         | web,auth                     | 
|        | POST     | admin/city/{city}/delete                                 | delete.city         | App\Http\Controllers\CityController@destroy                            | web,auth                     | 
|        | GET|HEAD | admin/dashboard                                          | home                | App\Http\Controllers\HomeController@index                              | web,auth                     | 
|        | GET|HEAD | admin/discounts                                          | discounts.index     | App\Http\Controllers\DiscountController@index                          | web,auth                     | 
|        | GET|HEAD | admin/discounts/add                                      | discounts.create    | App\Http\Controllers\DiscountController@create                         | web,auth                     | 
|        | POST     | admin/discounts/store                                    | discounts.store     | App\Http\Controllers\DiscountController@store                          | web,auth                     | 
|        | GET|HEAD | admin/discounts/{discount}                               | view.discount       | App\Http\Controllers\DiscountController@show                           | web,auth                     | 
|        | GET|HEAD | admin/faqs                                               | faqs.index          | App\Http\Controllers\FaqController@index                               | web,auth                     | 
|        | GET|HEAD | admin/faqs/add                                           | faqs.create         | App\Http\Controllers\FaqController@create                              | web,auth                     | 
|        | POST     | admin/faqs/store                                         | faqs.store          | App\Http\Controllers\FaqController@store                               | web,auth                     | 
|        | GET|HEAD | admin/states                                             | states.index        | App\Http\Controllers\StateController@index                             | web,auth                     | 
|        | GET|HEAD | admin/states/add                                         | states.create       | App\Http\Controllers\StateController@create                            | web,auth                     | 
|        | POST     | admin/states/store                                       | states.store        | App\Http\Controllers\StateController@store                             | web,auth                     | 
|        | GET|HEAD | admin/states/{state}                                     | view.state          | App\Http\Controllers\StateController@show                              | web,auth                     | 
|        | GET|HEAD | admin/states/{state}/add-city                            | cities.create       | App\Http\Controllers\CityController@create                             | web,auth                     | 
|        | POST     | admin/states/{state}/store-city                          | cities.store        | App\Http\Controllers\CityController@store                              | web,auth                     | 
|        | POST     | admin/store-media                                        | store.media         | App\Http\Controllers\StoreMediaController                              | web,auth                     | 
|        | GET|HEAD | admin/test                                               | test                | App\Http\Controllers\TestController                                    | web,auth                     | 
|        | GET|HEAD | admin/users                                              | users.index         | App\Http\Controllers\Admin\UserController@index                        | web,auth                     | 
|        | GET|HEAD | business-manager/businesses                              | businesses.index    | App\Http\Controllers\BusinessController@index                          | web,can:manage-businesses    | 
|        | GET|HEAD | business-manager/home                                    | manager.home        | Closure                                                                | web,can:manage-businesses    | 
|        | POST     | business-request                                         | request.business    | App\Http\Controllers\BusinessRequestController@store                   | web                          | 
|        | GET|HEAD | club/{state}/{city}                                      | public.city         | App\Http\Controllers\PagesController@city                              | web,auth                     | 
|        | POST     | club/{state}/{city}/city-notify-request                  | mc.notify.city      | App\Http\Controllers\MailchimpNotifyCityController                     | web                          | 
|        | POST     | club/{state}/{city}/register                             | signup.user         | App\Http\Controllers\ClubSignupController@signupUser                   | web                          | 
|        | GET|HEAD | club/{state}/{city}/request-card                         | public.signup       | App\Http\Controllers\PagesController@signup                            | web,auth                     | 
|        | GET|HEAD | club/{state}/{city}/thank-you                            | signup.complete     | App\Http\Controllers\ClubSignupController@thanks                       | web                          | 
|        | GET|HEAD | club/{state}/{city}/{business}/{discount}                | public.discount     | App\Http\Controllers\PagesController@discount                          | web,auth                     | 
|        | GET|HEAD | clubs/all-cities                                         | public.cities.list  | App\Http\Controllers\PagesController@allCities                         | web,auth                     | 
|        | GET|HEAD | contact-us                                               | public.contact      | App\Http\Controllers\PagesController@contact                           | web,auth                     | 
|        | POST     | email/resend                                             | verification.resend | App\Http\Controllers\Auth\VerificationController@resend                | web,auth,throttle:6,1        | 
|        | GET|HEAD | email/verify                                             | verification.notice | App\Http\Controllers\Auth\VerificationController@show                  | web,auth                     | 
|        | GET|HEAD | email/verify/{id}/{hash}                                 | verification.verify | App\Http\Controllers\Auth\VerificationController@verify                | web,auth,signed,throttle:6,1 | 
|        | GET|HEAD | faqs                                                     | public.faqs         | App\Http\Controllers\PagesController@faqs                              | web,auth                     | 
|        | GET|HEAD | login                                                    | login               | App\Http\Controllers\Auth\LoginController@showLoginForm                | web,guest                    | 
|        | POST     | login                                                    |                     | App\Http\Controllers\Auth\LoginController@login                        | web,guest                    | 
|        | POST     | logout                                                   | logout              | App\Http\Controllers\Auth\LoginController@logout                       | web                          | 
|        | GET|HEAD | password/confirm                                         | password.confirm    | App\Http\Controllers\Auth\ConfirmPasswordController@showConfirmForm    | web,auth                     | 
|        | POST     | password/confirm                                         |                     | App\Http\Controllers\Auth\ConfirmPasswordController@confirm            | web,auth                     | 
|        | POST     | password/email                                           | password.email      | App\Http\Controllers\Auth\ForgotPasswordController@sendResetLinkEmail  | web                          | 
|        | GET|HEAD | password/reset                                           | password.request    | App\Http\Controllers\Auth\ForgotPasswordController@showLinkRequestForm | web                          | 
|        | POST     | password/reset                                           | password.update     | App\Http\Controllers\Auth\ResetPasswordController@reset                | web                          | 
|        | GET|HEAD | password/reset/{token}                                   | password.reset      | App\Http\Controllers\Auth\ResetPasswordController@showResetForm        | web                          | 
|        | GET|HEAD | privacy-policy                                           | public.privacy      | App\Http\Controllers\PagesController@privacy                           | web,auth                     | 
|        | GET|HEAD | register                                                 | register            | App\Http\Controllers\Auth\RegisterController@showRegistrationForm      | web,guest                    | 
|        | POST     | register                                                 |                     | App\Http\Controllers\Auth\RegisterController@register                  | web,guest                    | 
|        | GET|HEAD | states/{state}                                           | public.state        | App\Http\Controllers\PagesController@state                             | web,auth                     | 
|        | POST     | telescope/telescope-api/cache                            |                     | Laravel\Telescope\Http\Controllers\CacheController@index               | telescope                    | 
|        | GET|HEAD | telescope/telescope-api/cache/{telescopeEntryId}         |                     | Laravel\Telescope\Http\Controllers\CacheController@show                | telescope                    | 
|        | POST     | telescope/telescope-api/commands                         |                     | Laravel\Telescope\Http\Controllers\CommandsController@index            | telescope                    | 
|        | GET|HEAD | telescope/telescope-api/commands/{telescopeEntryId}      |                     | Laravel\Telescope\Http\Controllers\CommandsController@show             | telescope                    | 
|        | POST     | telescope/telescope-api/dumps                            |                     | Laravel\Telescope\Http\Controllers\DumpController@index                | telescope                    | 
|        | POST     | telescope/telescope-api/events                           |                     | Laravel\Telescope\Http\Controllers\EventsController@index              | telescope                    | 
|        | GET|HEAD | telescope/telescope-api/events/{telescopeEntryId}        |                     | Laravel\Telescope\Http\Controllers\EventsController@show               | telescope                    | 
|        | POST     | telescope/telescope-api/exceptions                       |                     | Laravel\Telescope\Http\Controllers\ExceptionController@index           | telescope                    | 
|        | GET|HEAD | telescope/telescope-api/exceptions/{telescopeEntryId}    |                     | Laravel\Telescope\Http\Controllers\ExceptionController@show            | telescope                    | 
|        | PUT      | telescope/telescope-api/exceptions/{telescopeEntryId}    |                     | Laravel\Telescope\Http\Controllers\ExceptionController@update          | telescope                    | 
|        | POST     | telescope/telescope-api/gates                            |                     | Laravel\Telescope\Http\Controllers\GatesController@index               | telescope                    | 
|        | GET|HEAD | telescope/telescope-api/gates/{telescopeEntryId}         |                     | Laravel\Telescope\Http\Controllers\GatesController@show                | telescope                    | 
|        | POST     | telescope/telescope-api/jobs                             |                     | Laravel\Telescope\Http\Controllers\QueueController@index               | telescope                    | 
|        | GET|HEAD | telescope/telescope-api/jobs/{telescopeEntryId}          |                     | Laravel\Telescope\Http\Controllers\QueueController@show                | telescope                    | 
|        | POST     | telescope/telescope-api/logs                             |                     | Laravel\Telescope\Http\Controllers\LogController@index                 | telescope                    | 
|        | GET|HEAD | telescope/telescope-api/logs/{telescopeEntryId}          |                     | Laravel\Telescope\Http\Controllers\LogController@show                  | telescope                    | 
|        | POST     | telescope/telescope-api/mail                             |                     | Laravel\Telescope\Http\Controllers\MailController@index                | telescope                    | 
|        | GET|HEAD | telescope/telescope-api/mail/{telescopeEntryId}          |                     | Laravel\Telescope\Http\Controllers\MailController@show                 | telescope                    | 
|        | GET|HEAD | telescope/telescope-api/mail/{telescopeEntryId}/download |                     | Laravel\Telescope\Http\Controllers\MailEmlController@show              | telescope                    | 
|        | GET|HEAD | telescope/telescope-api/mail/{telescopeEntryId}/preview  |                     | Laravel\Telescope\Http\Controllers\MailHtmlController@show             | telescope                    | 
|        | POST     | telescope/telescope-api/models                           |                     | Laravel\Telescope\Http\Controllers\ModelsController@index              | telescope                    | 
|        | GET|HEAD | telescope/telescope-api/models/{telescopeEntryId}        |                     | Laravel\Telescope\Http\Controllers\ModelsController@show               | telescope                    | 
|        | POST     | telescope/telescope-api/monitored-tags                   |                     | Laravel\Telescope\Http\Controllers\MonitoredTagController@store        | telescope                    | 
|        | GET|HEAD | telescope/telescope-api/monitored-tags                   |                     | Laravel\Telescope\Http\Controllers\MonitoredTagController@index        | telescope                    | 
|        | POST     | telescope/telescope-api/monitored-tags/delete            |                     | Laravel\Telescope\Http\Controllers\MonitoredTagController@destroy      | telescope                    | 
|        | POST     | telescope/telescope-api/notifications                    |                     | Laravel\Telescope\Http\Controllers\NotificationsController@index       | telescope                    | 
|        | GET|HEAD | telescope/telescope-api/notifications/{telescopeEntryId} |                     | Laravel\Telescope\Http\Controllers\NotificationsController@show        | telescope                    | 
|        | POST     | telescope/telescope-api/queries                          |                     | Laravel\Telescope\Http\Controllers\QueriesController@index             | telescope                    | 
|        | GET|HEAD | telescope/telescope-api/queries/{telescopeEntryId}       |                     | Laravel\Telescope\Http\Controllers\QueriesController@show              | telescope                    | 
|        | POST     | telescope/telescope-api/redis                            |                     | Laravel\Telescope\Http\Controllers\RedisController@index               | telescope                    | 
|        | GET|HEAD | telescope/telescope-api/redis/{telescopeEntryId}         |                     | Laravel\Telescope\Http\Controllers\RedisController@show                | telescope                    | 
|        | POST     | telescope/telescope-api/requests                         |                     | Laravel\Telescope\Http\Controllers\RequestsController@index            | telescope                    | 
|        | GET|HEAD | telescope/telescope-api/requests/{telescopeEntryId}      |                     | Laravel\Telescope\Http\Controllers\RequestsController@show             | telescope                    | 
|        | POST     | telescope/telescope-api/schedule                         |                     | Laravel\Telescope\Http\Controllers\ScheduleController@index            | telescope                    | 
|        | GET|HEAD | telescope/telescope-api/schedule/{telescopeEntryId}      |                     | Laravel\Telescope\Http\Controllers\ScheduleController@show             | telescope                    | 
|        | POST     | telescope/telescope-api/toggle-recording                 |                     | Laravel\Telescope\Http\Controllers\RecordingController@toggle          | telescope                    | 
|        | POST     | telescope/telescope-api/views                            |                     | Laravel\Telescope\Http\Controllers\ViewsController@index               | telescope                    | 
|        | GET|HEAD | telescope/telescope-api/views/{telescopeEntryId}         |                     | Laravel\Telescope\Http\Controllers\ViewsController@show                | telescope                    | 
|        | GET|HEAD | telescope/{view?}                                        | telescope           | Laravel\Telescope\Http\Controllers\HomeController@index                | telescope                    | 
|        | GET|HEAD | terms-of-use                                             | public.terms        | App\Http\Controllers\PagesController@terms                             | web,auth                     | 
+--------+----------+----------------------------------------------------------+---------------------+------------------------------------------------------------------------+------------------------------+ 
Nakov's avatar
Nakov
Best Answer
Level 73

@whoisthisstud and from the Network tab in your browser, are you sure you are hitting this route that produces the error, or you might be hitting the / route which is GET?

Can you add quotes on the url:

url: "{{ route('request.business') }}",

or try this instead:

url: '/business-request',

Please or to participate in this conversation.