php - POST 方法的 Laravel + Vue + Axios 问题

标签 php laravel vue.js axios plesk

我正在开发一个存储在 VPS 上的 Laravel 5.6 项目(我们称之为“生产”,尽管没有这样的创建环境)。

我们还结合了 Plesk 和 Github,手动将 Web 应用程序从我们的本地环境部署到服务器。

问题 是当我从 API 加载一些数据时,它们返回错误 405 Method not allowed (GET)... 但它们实际上被注册为 POSTapp.jsroutes/api.php 中。

最棒的是,它们在我的本地环境中完美运行。

这里有一些信息:

服务器:

  • Ubuntu 服务器 14.04
  • Apache/MySQL
  • PHP 7.2.5

我的电脑:

  • 带有 XAMPP 的 Windows 10
  • Apache/MySQL
  • PHP 7.2.2

每个浏览器中的开发者工具:

Request Method: GET
Status Code: 405 Method Not Allowed

下面是 app.js 中的代码:

loadCountries: function loadCountries(total) {
    axios.post('/api/properties/countries/').then(function (response) {
        app.countries = response.data;
    });

    total = total <= this.countries.length ? total : this.countries.length;

    if (total) {
        var newArr = [];
        for (i = 0; i < total; i++) {
            newArr.push(this.countries[i]);
        }
        this.countries = newArr;
    }
},

注意:如果我在开发者工具中编辑同一个请求并再次发送它,但它作为 POST 请求返回给我一切正常,所以 API 似乎在 POST 请求上工​​作正常。

最佳答案

尝试删除网址中的尾部斜杠。

比如,

/api/properties/countries

替换原来的 app.js 中的那一行会产生这个,

loadCountries: function loadCountries(total) {
axios.post('/api/properties/countries').then(function (response) {
    app.countries = response.data;
});

total = total <= this.countries.length ? total : this.countries.length;

if (total) {
    var newArr = [];
    for (i = 0; i < total; i++) {
        newArr.push(this.countries[i]);
    }
    this.countries = newArr;
}

},

关于php - POST 方法的 Laravel + Vue + Axios 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50458911/

相关文章:

javascript - 我如何将值从谷歌云函数(firebase)传递到前端?

php - 如何在 Laravel 中保存多个复选框

php - 用php处理大文件到数据库

php - 包含日期和时间的字段不会与 Laravel 中的另一个进行比较

vue.js - 使用 nuxt-link 导航到不同页面上的 anchor /哈希不起作用

javascript - Vue.js vue-video-player 渲染 100px 宽

php - 安卓 PHP MySql

php - htmlentities 不适用于单引号

javascript - 在 php 中使用下拉菜单排序和检索数据

php - 查看在谷歌日历中创建的每个事件的 session 链接