【发布时间】:2020-01-15 08:46:41
【问题描述】:
大家早上好,
我使用:“laravel/framework”:“^6.2”, "axios": "^0.19", "vue": "^2.5.17",
当我使用 axios.put 和 route put 我的 response.data 是正确的(response.data:“ok”)时我遇到了问题,但是在我的 axios.post 和 route post 中,我在 response.data 中收到了一个 html我不明白为什么有人可以解释一下?以及如何在我的 axios.post 中获得一个 reponse.data:"ok"?
文件.vue
let formData = new FormData();
formData.append('connexion', this.customer);
formData.append('product', this.product);
axios.post('hosting/', formData)
.then(response=> {
console.log(response);
});
文件路径
Route::post('hosting', ['uses' => 'Api\HostingController@cart']);
文件控制器
public function cart(Request $request)
{
return 'ok';
}
我在 axios.post 时的回应
我在 axios.put 时的回应
感谢您的帮助!
【问题讨论】:
-
可以显示整个 HTML 吗?
-
他只是归还了我的主刀。
-
您是否尝试过在请求头字段中添加 'Accept': 'application/json' ?在返回数据时使用
return response()->json(/* your data here */)?
标签: laravel vue.js vuejs2 axios