人员信息的表单提交。其中有一项图片的提交
<form id="empForm" method="post" novalidate="novalidate">
<table style="margin-top: 50px;" align="center">
<tr>
<td>
<label for="empName">姓 名:</label>
<input class="easyui-textbox" id="empName" name="empName" style="width:180px"/>
</td>
</tr>
<tr>
<td>
<label for="empNo">员工编号:</label>
<input class="easyui-textbox" id="empNo" name="empNo" style="width:180px"/>
</td>
</tr>
<tr>
<td>
<label for="empCardno">身份证号:</label>
<input class="easyui-textbox" id="empCardno" name="empCardno" style="width:180px"/>
</td>
</tr>
<tr>
<td>
<label for="empSex">性 别:</label>
<select class="easyui-combobox" id="empSex" name="empSex" style="width:180px">
<option value="0">女</option>
<option value="1">男</option>
<option value="2">未知</option>
</select>
</td>
</tr>
<tr>
<td>
<label for="empStation">岗位名称:</label>
<input class="easyui-textbox" id="empStation" name="empStation" style="width:180px"/>
</td>
</tr>
<tr>
<td>
<label for="joinTime">入职时间:</label>
<input class="easyui-datebox" id="joinTime" name="joinTime" style="width:180px"/>
</td>
</tr>
<%-- <label for="empPhoto">人员照片:</label>--%>
<%-- <input class="easyui-filebox" id="empPhoto" name="empPhoto" style="width:150px"/>--%>
<tr>
<td><label for="empPhoto"> 人员照片: </label>
<input multiple style="width:180px" id="empPhoto" name="empPhoto" class="easyui-filebox"
data-options='onChange:change_photo'></td>
</tr>
<tr>
<td><label for="empPhoto">图片预览:</label>
<div id="Imgdiv"><img id="Img" width="180px" height="200px"/></div>
</td>
</tr>
</table>
</form>
<script type="text/javascript">
$(function () {
$('#empPhoto').filebox({
buttonText: '选择图片',
buttonAlign: 'right',
onChange: function (data) { // data------->>"C:\\fakepath\\1.jpg"
debugger
var fd = new FormData();
var file = document.getElementsByName("empPhoto")[0].files[0];//name: "2.jpg"
//的参数名 参数值 k-v键值对
fd.append("empPhoto", file);
debugger
$.ajax({
url:'${pageContext.request.contextPath}/emp/uploadPhoto.do',
type:"post",
data:fd,
cache: false,
processData: false,
contentType: false,
success:function(data){
var result = eval('(' + data + ')');
if (result.success) {
alert("文件成功!" + result.successMsg,);
}
$.messager.alert("提示",result.message);
},
error:function(e){
$.messager.alert("错误","服务器异常,请稍后重试!!!
"+e.message);
}
});
}
})
})