gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-30 22:16:43 25 4
gpt4 key购买 nike

我正在开发一个存储在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com