JSP 端:ajax
<img id="uploadImg" src="" onclick="document.getElementById('files').click()"/>json
<form id="form" enctype="multipart/form-data" target="exec_target" method="post" >
<input id="files" name="files" type="file">
</form>post
JS端:url
var formData = new FormData(document.getElementById("form"));orm
$.ajax({
url: '請求地址',
type:"post",
data:formData,
processData:false,
contentType:false,圖片
dataType : 'json',
success: function(reponse) {
alert("圖片上傳成功!");
},
error: function(e) {
alert("ERROR >>> " + e);
}
})ip