页面标签 <input type=file id=file />
var data = new FormData();
data.append("name", $("#name").val());//可以传字符串参数
data.append("file", document.getElementById("file").files[0]);//文件直接放进去
$.ajax({
url: "api/file-upload",
type: "post",
data: data,
processData: false, //tell jQuery not to process the data
contentType: false, //tell jQuery not to set contentType
success: function (data) {
alert(data);
}
});
用自定义图片的click关联file的click,满足一切样式需求.