<form enctype='multipart/form-data' method='post' action='javascript:;' id="frmUploadFile">
<input type = "file" name = "pictureFile" class = "form-control" onchange = "uploadFile()" />
</form>
<script type="text/javascript">
function uploadFile(){
var formData = new FormData($("#frmUploadFile")[0]);
$.ajax({
url: '/image/upload',
type: 'POST',
data: formData,
async: false,
cache: false,
contentType: false,
processData: false,
success: function(data){
console.log( data);
$("#headPortrait").attr({ src: "/image/getImg?path="+data.filePath});
},
error: function(){
$("#spanMessage").html("与服务器通信发生错误");
}
});
}
</script>
js上传文件
最新推荐文章于 2024-07-15 15:43:52 发布