0
我有一個表單,我試圖用圖像文件提交。Laravel AJAX表單不發送圖像數據
問題是沒有圖像文件正在發送。
我的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: {}
有什麼幫助嗎?
結帳這篇文章,也許它可以幫助:http://stackoverflow.com/questions/10899384/uploading-both-data-and-files-in-one-form-using-ajax –