52,797
社区成员
发帖
与我相关
我的任务
分享
var file = document.getElementById('file').files[0];
var deptId = $("#deptId").val();
var fd = new FormData();
fd.append("deptId",deptId);
ajaxPostImage("/xxxxx.do", field, function (res) {
//......
function ajaxPostImage(url,data,callback) {
var index;
$.ajax({
url:url,
async: false,
dataType:"json",
processData: false, //tell jQuery not to process the data
contentType: false, //tell jQuery not to set contentType
beforeSend: function () {
//......
},
complete: function(){
//......
},
data:data,
type:"post",
success:function(data){
callback(data);
},
error:function(){
//......
}
});
}
<form action="/user/upload/tuxiang" enctype="multipart/form-data" method="POST">
<input type="file" name="photo" />
<input type="submit" value="Upload Photo"/>
</form>