M
M
maxpaun2020-07-14 11:05:48
Laravel
maxpaun, 2020-07-14 11:05:48

Why does an error occur when sending a post request: 405 (Method Not Allowed)?

I make a post request, in response I get an error 405 (Method Not Allowed). At the same time, csrf-token backed up too. Interestingly, exactly the same method works fine on another project, but Laravel is a little older there.

bootstrap.js

window.axios = require('axios');
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
window.axios.defaults.headers.common['X-CSRF-TOKEN'] = document.querySelector('meta[name="csrf-token"]').getAttribute('content');


app.js
...
getCartData: function (){
        return window.axios.post('/show-cart')
          .then(response => response.data)
          .then(cart => {
            this.products = cart['products'];
            this.itemsCount = cart['quantity'];
            this.cartAmount = cart['amount'];
          });
      },
...


route/web.php
Auth::routes();
Route::get('/show-cart', 'Admin\[email protected]');


And, yes, if you try to open the /show-cart path in the browser, then everything works fine.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2020-07-14
@maxpaun

axios.post('/show-cart'

Route::get('/show-cart'

Method not allowed, meaning POST GET

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question