为什么我不能将 FormData 对象值发送到我的 Laravel 应用程序
Javascript 代码:
console.log("Sending start...")
for (var value of company.values()) {
console.log(value);
}
this.$axios.put(url, company)
.then(res => {
console.log(res)
})
.catch(error => {
console.log(error)
})
响应预览:
Laravel Controller :
public function update(Request $request, Company $company)
{
return response()->json($request->all());
}
哪里出错了?
最佳答案
尝试通过发送 POST
请求来欺骗 Laravel 框架,其中 axios
将方法类型作为 PUT
分配给 FormData
对象。
代码:
// Lets create FormData object
let data = new FormData()
data.append('_method', 'PUT')
// ...........................
// other your appends here...
// Axios request
this.$axios.post(url, data)
.then(res => {
console.log(res)
})
检查后,让我知道代码的结果:)
关于javascript - 为什么带有 FormData 对象的 PUT 请求没有发送到 Laravel Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58024068/