ajax提交文件

form表单

<form method="post" enctype="multipart/form-data" action="">
    <input name="file" type="file" accept=".txt,.html" multiple="multiple"/>
form>

js

//获取文件表单数据
var formData = new FormData($("#fileUploadForm")[0]);  
$.ajax({
     url: url,
     type: 'POST',
     data: formData,
     dataType:"json",
     async: false,
     cache: false,
     contentType: false,
     processData: false,
     success: function (data) {
           alert(data.message);
     },
     error: function (data) {
        alert("保存失败");
     }
});

你可能感兴趣的:(ajax)