【问题标题】:405 (Method Not Allowed) Axios - Laravel405(方法不允许)Axios - Laravel
【发布时间】:2020-07-25 09:05:54
【问题描述】:

我正在尝试创建一个表单,用户在其中填写一些数据,然后将数据提交到服务器

 methods: {
    sendOrder () {
        this.loading = true;
        axios.post ('/send/', {
           firstName: this.firstName,
           lastName: this.lastName,
           phone: this.phone,
           delivery: this.delivery,
           ... (this.delivery? {address: this.address}: {}),
           note: this.note,
           items: this.items,
           total: this.total

        })

这在我的本地服务器上效果很好,但是当我在真实服务器上设置时,我在控制台中收到以下错误:

http://my-website.com/email-sender/public/send 405 (Method Not Allowed)

我怀疑你可以看到的这部分回复...email-sender/public...

这可能是由于错误的 .htaccess 设置吗?

另外,当我通过邮递员向同一路线发出发布请求时,我收到此错误:

Status: 419 unknown status

我将请求发送到http://my-webiste.com/send 或

都没有关系

http://my-webiste.com/public/email-sender/send邮递员的错误总是419。

路线(来自评论):

Route::get('/', 'OrderController@index');
Route::get('/thankyou', 'OrderController@thankyou');
Route::post('/send', 'OrderController@send');

【问题讨论】:

  • 请显示您的路线。
  • Route::get('/', 'OrderController@index'); Route::get('/thankyou', 'OrderController@thankyou'); Route::post('/send', 'OrderController@send');
  • /send/ 和 /send 可能是不同的网址。此外,Laravel 中的 public 文件夹应该是您的项目/服务器的“DocumentRoot”,并且不会出现在您的网址中
  • 我在 axios 方法和 web.php 中都将路由更改为 /send,但仍然出现相同的错误。我不知道为什么项目根目录出现在 url 中。

标签: laravel vue.js post axios


【解决方案1】:

我解决了这个问题。具体来说,问题出在 .htaccess 文件中,它没有很好地指向 Laravel 应用程序的公共根目录。

以前,我有一个公用文件夹和一个 Laravel 项目文件夹,我必须更改它们才能使所有 Laravel 文件都位于该根文件夹中。

现在,在 url 中显示整个路径的问题以及代码 419 的问题都消失了。我希望我正确地解释了问题的解决方案。

【讨论】:

    猜你喜欢
    • 2023-02-17
    • 2021-07-07
    • 2020-05-24
    • 2017-11-28
    • 2017-05-31
    • 1970-01-01
    • 2021-12-07
    • 2018-10-14
    • 2021-12-12
    相关资源
    最近更新 更多