我正在开发一个存储在 VPS 上的 Laravel 5.6 项目(我们称之为“生产”,尽管没有这样的创建环境)。
我们还结合了 Plesk 和 Github,手动将 Web 应用程序从我们的本地环境部署到服务器。
问题 是当我从 API 加载一些数据时,它们返回错误 405 Method not allowed (GET)... 但它们实际上被注册为 POST 在 app.js
和 routes/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/