0
私はAjaxのやり取りを通してファイルをアップロードしています。私は、一緒に、サーバー側でパスを構築するための情報を送信したいと思います。しかし、私はそれが可能かどうか、私はそれをどうすることができるかは分かりません。他のデータをajaxのファイルと一緒に送ることは可能ですか?
function uploadFD(){
var oMyForm = new FormData();
jQuery.each(jQuery('#file')[0].files, function(i, file) {
oMyForm.append('file-'+i, file);
});
$.ajax({
url: 'FileController',
data: oMyForm,
processData: false,
contentType: false,
type: 'POST',
success: function(data){
$('#Result').html(data.msg);
$.messager.show({
title : 'Success',
msg : data.msg,
showType : 'show'
});
}
});
}
コントローラー:
@RequestMapping(method = RequestMethod.POST, headers = "content-type=multipart/*")
public void upload(MultipartHttpServletRequest request,
HttpServletResponse response) {
response.setCharacterEncoding("UTF-8");
Iterator<String> itr = request.getFileNames();
MultipartFile mpf = request.getFile(itr.next());
System.out.println(mpf.getOriginalFilename() +" uploaded!");
//... other stuff
}
私はそれをどのように行うことができますか?ありがとう!
あなたが 'oMyForm.appendを()'を使用することができますフォームデータに他のパラメータを追加します。 – Barmar