JS:How to send multiple files using FormData(jQuery Ajax)
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
In my form multiple file uploads are there,using FormData only one file is uploading ,though I'm selecting more than one file to upload,following is the code
The previous answer has a little error that was fixed on the next code, and gonna works to send multiple files via ajax:
var formData = new FormData(); $.each($(".TheFiles"), function (i, obj) { $.each(obj.files, function (j, file) { formData.append('Attachment[' + i + ']', file); // is the var i against the var j, because the i is incremental the j is ever 0 }); }); formData.append('Destination', Destination); //add more variables that you need formData.append('ReplyTo', ReplyTo);//add more variables that you need formData.append('Body', Body);//add more variables that you need
optionally just for you can see my ajax config
回答3:
Those answers do not work.
var ajaxData = new FormData(); ajaxData.append( 'action','uploadImages'); $.each($("input[type=file]"), function(i, obj) { $.each(obj.files,function(j,file){ ajaxData.append('photo['+j+']', file);//i had to change "i" by "j" }) });
回答4:
in front end
at the backend (nodejs) add this(using multer)
var multer=require('multer') app.post('/test',upload.array('photo[]',6),function(req ,res,next){ var images=[] if(req.files){ for(var i=0;i