405(不允许使用方法)Axios-Laravel

时间:2020-04-12 19:43:38

标签: laravel vue.js post axios

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

 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');

1 个答案:

答案 0 :(得分:0)

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

以前,我在其中有一个公用文件夹和一个Laravel项目文件夹,为了使所有Laravel文件都位于该根文件夹中,我必须对其进行更改。

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