[英]Fileupload Closest tr in Jquery
HTML HTML
<table>
<tr>
<td> <input type="file" /> </td>
<td> <input type="button" id="btn" /> </td>
</tr>
<tr>
<td> <input type="file" /> </td>
<td> <input type="button" id="btn" /> </td>
</tr>
<tr>
<td> <input type="file" /> </td>
<td> <input type="button" id="btn" /> </td>
</tr>
</table>
JQUERY JQUERY
var formData = new FormData();
var tr = $(this).closest('tr');
var fup = $(tr).find("input[type='file']");
var totalFiles = fup.length;//Here, getting total file count
for (var i = 0; i < totalFiles; i++) {
var file = fup.file[i];//I am getting exception here
formData.append("fupUpdate", file);
}
I am unable to get the list of files appended to formdata. 我无法获取附加到formdata的文件列表。
Error Message: "Cannot read property '0' of undefined"
Please assist me in resolving the issue. 请协助我解决问题。
Try this code 试试这个代码
var fData = new FormData();
var tr = $('table').closest('tr');
var fup = $('tr').find("input[type='file']");
var totalFiles = fup.length;//Here, getting total file count
for (var i = 0; i < totalFiles; i++) {
var file = fup[i].files[0];//Exception will not occur here
console.log(file)
fData.append("fupUpdate", file);
}
Do not create local variable with the same name as FormData 不要创建与FormData同名的局部变量
You are doing right just replace 你做得对,只需更换
var file = fup.file[i];//I am getting exception here
with 同
var file = fup[i].files[0];// no Exception here.
and this will work fine. 这将工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.