我面临多个文件上传的问题。问题是:如果我上传 2 个,files只有 1 个文件被发送到后端。只将最后一个文件发送到服务器(跳过其他文件,即只发送 1 个文件到后端)问题:我有一种情况,在每次输入时,我可以浏览多个文件并可以单击提交。我希望每个文件都应该发送到服务器。这里:jsfiddle显示我的问题:http : //jsfiddle.net/eabangalore/jyteus6c/2/注意:请console.log检查是否全部files发送到服务器。下面是我的代码:var filesUploadList = [];function initializeMultipleFileUpload(){ fileList.forEach(function(obj){ $('input[data-id="'+obj.identifier+'"]').fileupload({ url: 'https://jsonplaceholder.typicode.com/posts', autoUpload: false, maxChunkSize: 10*1024*1024, // 1MB maxRetries: 10, dataType: 'json', multipart: false, sequentialUploads: true, replaceFileInput: false, progress: function(e,data){ console.log('Progress for file Name: ',data.data.name); }, }).on("fileuploadadd", function (e, data) { filesUploadList.push(data.files[0]) }); });}var fileList = [ {'fileNo':1,identifier:111}, {'fileNo':2,identifier:222}, {'fileNo':3,identifier:33}];var inputFileStr = '';for(var i = 0; i< fileList.length; i++){ inputFileStr += '<input type="file" multiple data-id="'+fileList[i].identifier+'"><button data-buttonid="'+fileList[i].identifier+'" class="comm-submit-btn">submit</button>';}$('#multiplefiles').html(inputFileStr);initializeMultipleFileUpload(); //initialize fileupload here$(document).ready(function () { $(".comm-submit-btn").click(function () { var fileUploadInputId = $(this).attr('data-buttonid'); console.log('.....filesUploadList.........',filesUploadList); $('input[data-id="'+fileUploadInputId+'"]').fileupload('send', {files: filesUploadList }); })});
添加回答
举报
0/150
提交
取消