1.引入js,javascript
<script type="text/javascript"
src="<%=request.getContextPath()%>/resources/js/ajaxFile/jquery.js" charset="utf-8"></script>
<script type="text/javascript"
src="<%=request.getContextPath()%>/resources/js/ajaxFile/ajaxfileupload.js" charset="utf-8"></script>java
2.將表單的內容轉換爲jsonjquery
<script type="text/javascript"
src="<%=request.getContextPath()%>/resources/js/workorder-page-utils.js" charset="utf-8"></script>ajax
3.異步上傳json
$.ajaxFileUpload({
url : '<%=request.getContextPath()%>/fileUpload/upload',//表單上傳的路徑
secureuri : false,
fileElementId : 'filename', //上傳文件input的id
dataType : 'json', //數據傳輸格式爲josn
data : $("#workorderForm3").serializeObject(), //將表單數據序列化爲json
success : function(data) {
var annexsJson="";
annexsJson+=data.annexName+",";
annexsJson+=data.annexType+",";
annexsJson+=data.annexUrl+",";
$("#annexsJson").val(annexsJson);
},
error : function(data, status, e) {
alert('上傳出錯');
}
});異步