【发布时间】:2015-11-16 19:46:57
【问题描述】:
我想提交一个带有图像文件的表单。
问题是没有发送图像文件。
我的 AJAX 调用:
$(document).on('submit', ".hidden-image-upload", function(e){
e.preventDefault();
$.ajax({
url:'/project/uploadImage',
data: new FormData($(".hidden-image-upload")[0]),
headers: {
'X-CSRF-Token': $('form.hidden-image-upload [name="_token"]').val()
},
dataType:'json',
async:false,
type:'post',
processData: false,
contentType: false,
success:function(response){
console.log(response);
},
});
});
然后是我的表格:
{!! Form::open(['class' => 'hidden-image-upload', 'files' => true]) !!}
{!! Form::file('file', ['class' => 'cover-image-upload-button']) !!}
{!! Form::close() !!}
在我的控制器中,我只是返回:
return $request->all();
我得到:
_token: "lFHIf7wiYI3IWqrbcpKxgJEPtXCIVpLm5nVhJ1Ks", file: {}}
_token: "lFHIf7wiYI3IWqrbcpKxgJEPtXCIVpLm5nVhJ1Ks"
file: {}
有什么帮助吗?
【问题讨论】:
-
查看这篇文章,也许它会有所帮助:stackoverflow.com/questions/10899384/…