php – 请求对象在流明api中是空的
发布时间:2020-12-13 22:28:10 所属栏目:PHP教程 来源:网络整理
导读:使用ajax调用在流明API中上传图像文件,它没有将图像放入流明中进行处理,请求对象为空. Ajax调用 var file = $('#img')[0].files[0];var form_data = new FormData(document.getElementById("myform"));form_data.append("img",file);$.ajax({ url: "http://l
使用ajax调用在流明API中上传图像文件,它没有将图像放入流明中进行处理,请求对象为空.
Ajax调用 var file = $('#img')[0].files[0]; var form_data = new FormData(document.getElementById("myform")); form_data.append("img",file); $.ajax({ url: "http://localhost:8000/api/image",type: "POST",data: form_data,enctype: 'multipart/form-data',processData: false,// tell jQuery not to process the data contentType: false // tell jQuery not to set contentType }) .done(function (data) { console.log(data); }); 路线 $api->post('/image','ImagesController@addImage'); 调节器 public function addImage(Request $request) { return $request; // returns empty object } Request payload Response 解决方法
在你的控制器中添加这一行
use IlluminateHttpRequest; 不要使用请求外观,因为Lumen与Laravel的工作方式不同. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |