Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.1 AJAX - Returning 405 GET Method Not Allowed even when I am sending a POST request

My Laravel POST route returns 405 GET Method not allowed when I am sending a POST request through AJAX. However the problem is that it works in localhost but not working in Heroku production server. My AJAX POST request gets sent as GET request to the route. Below i have attached a screenshot and my AJAX code.

$.ajax({
            url: url,
            type: 'POST',
            data: data,
            contentType: 'application/json',
            headers: {
                'X-CSRF-TOKEN': token
            }
        })

My route is configured as:

Route::post('/adminpanel/projects/delete/', 'AdminPanelController@deleteData');

enter image description here

like image 743
ChanX Avatar asked Nov 19 '15 06:11

ChanX


2 Answers

Update your action url from

/adminpanel/projects/delete/

into

/adminpanel/projects/delete
                        //^^ Removed that slash

Remove that slash and it'll work for you.

like image 59
Narendrasingh Sisodia Avatar answered Nov 04 '22 16:11

Narendrasingh Sisodia


If you are using a resource in Laravel, then check the routes list by command :

php artisan route:list

See, If the POST request you are trying to send is allowed in the routes or not. 405 error is generally because we forgot to mention the request in the routes.

like image 36
stackMonk Avatar answered Nov 04 '22 16:11

stackMonk