H5W3
当前位置:H5W3 > 问答 > 正文

var formdata = new FormData($(“#uploadForm”)[0]);

江湖救急!
上传多个文件,传参失败。

var formdata = new FormData($(“#uploadForm”)[0]);

视图:
<form id=”uploadForm” enctype=”multipart/form-data”>
<input type=”file” name=”file” multiple=”multiple” />
</form>
<button id=”btnUpload”>上传文件</button>

脚本:

<script>

$("#btnUpload").on("click", function () {
var formdata = new FormData($("#uploadForm")[0]);
alert(formdata);
$.ajax({
type: "post",
url: "/Attendance/UploadFile2/",//url地址
contentType: false,
cache: false,
processData: false,
data: formdata,
success: function (data) {
console.log(data);
}
});
});

</script>

控制器:
var formdata = new FormData($(

files.Count 为0

回答

我用你的代码测试是可以的

将formdata改用下面的方式试下

        var formdata = new FormData();
        var files = $("input[type='file']")[0].files;
        for (var i = 0; i < files.length; i++) {
            formdata.append("file", files[i]);
        }

如果还是不行,就参照:https://www.cnblogs.com/lunawzh/p/9326619.html

本文地址:H5W3 » var formdata = new FormData($(“#uploadForm”)[0]);

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址