先看效果:
代码:
<form id="fileUpload" action="" method="post" enctype="multipart/form-data"> <input type="file" name="file" id="file"> <button type="submit">上传</button> </form>
$('#fileUpload').on('submit', function (e) { e.preventDefault(); // 不自动提交 var formData = new FormData(this); formData.append('xxx', xxx);//自定义参数。 formData.append('xxx', xxx); formData.append('xxx', xxx); formData.append('xxx', xxx); formData.append('xxx', xxx); formData.append('xxx', xxx); $.ajax({ url: 'https://www.liuguiqing.com:8080/fileupload', type: 'POST', data: formData, contentType: false, // 不管类型 processData: false, // 不管数据 success: function (response) { console.log(response); }, error: function (error) { console.error(error); } }); });
标签:jquery,function,formData,xxx,js,ajax,error,append From: https://www.cnblogs.com/liuguiqing/p/18387392