Ajax传Form表单,包括上传文件
生活随笔
收集整理的這篇文章主要介紹了
Ajax传Form表单,包括上传文件
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
被這個(gè)問題困擾了好久。。。真是醉了
借用了jquery 的插件,jquery-form.js,鏈接:http://jquery.malsup.com/form/#download
js代碼(options包含很多參數(shù),可以進(jìn)行設(shè)置)
<script?type="text/javascript">function?save(){var?options?=?{success:function(data){if(data.success==true)?{alert("保存成功");}}}//?當(dāng)沒有選擇上傳文件,如果還想正確提交時(shí)必須做以下處理if($("#pdfInput").val()==""){$("#pdfInput").remove();$("#uploadForm").attr("enctype",?"application/x-www-form-urlencoded");//或者不用remove()就設(shè)為disabled也可以//$("#pdfInput").attr("disabled",?"disabled");}$('#uploadForm').ajaxSubmit(options);} </script>Form表單
<form?action="${ctx}/StdManage/standardsUpdate"?id="uploadForm"?method="post"?enctype="multipart/form-data"><input?type="text"?name="id"><input?type="file"?name="stdFile"?id="pdfInput"> </form><button?type="button"?onclick="save()">save</button>Controller
@Controller("/StdManage") public?class?StdManageController{@RequestMapping("standardsUpdate")public?void?standardsUpdate(StandardWithBlobs?standardWithBlobs)?{System.out.println("id:"?+?standardWithBlobs.getId());} }StandardWithBlobs
package?whu.edu.irlab.model;import?org.springframework.web.multipart.MultipartFile;public?class?StandardWithBLOBs?extends?Standard{private?String?entities;private?String?possibleEntities;private?MultipartFile?stdFile;getter?and?setter?...? }轉(zhuǎn)載于:https://my.oschina.net/u/1020238/blog/528607
總結(jié)
以上是生活随笔為你收集整理的Ajax传Form表单,包括上传文件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: iOS 中捕获程序崩溃日志
- 下一篇: java重载和重载的区别