php - Laravel + Vue + Axios POST 方法的问题
问题描述
我正在开发一个存储在 VPS 上的 Laravel 5.6 项目(我们称之为“生产”,尽管没有这样的创建环境)。
我们还结合了 Plesk 和 Github,将 Web 应用程序从我们的本地环境手动部署到服务器。
问题是当我从 API 加载一些数据时,它们返回错误 405 Method not allowed ( GET )... 但它们实际上在和 in中注册为POST。app.js
routes/api.php
最棒的是,在我当地的环境中,它们可以完美运行。
这里有一些信息:
服务器:
- Ubuntu 服务器 14.04
- 阿帕奇/MySQL
- PHP 7.2.5
我的电脑:
- 带有 XAMPP 的 Windows 10
- 阿帕奇/MySQL
- PHP 7.2.2
每个浏览器中的开发者工具:
请求方法: GET
状态码: 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;
}
},
推荐阅读
- reactjs - 如何在 AEM Maven 项目中使用 Adobe 的 React Web Component 工具
- ninject - 如何将 Ninject 绑定到 [Obsolete] 构造函数?
- python-3.x - Python pika - 发布到不存在的交换不会引发异常
- c - 警告:初始化从指针目标类型中丢弃“const”限定符 [-Wdiscarded-qualifiers]
- c# - 是否可以在 TextChangeEvent 中为 TextBox 设置焦点
- android - 如何在 Kotlin 中完全实现 Navigation Drawer 模板
- salesforce - 内连接两个没有关系的 SOQL 对象
- facebook - 在没有任何 JS 框架的情况下在 Facebook 中分享 URL
- jquery - jQuery暗模式切换只工作了一半
- javascript - 我无法获得要渲染的基本球体