form提交时,ajax上传文件并更新到<input>中的value字段
想利用jsp做上传时,为了交互采用ajax上传附件,因此表单被我设计成这样
<form onsubmit="return FileUploadFunction(this)" enctype="multipart/form-data" method="post"> <c:forEach var="wjsInfo" items="${requestScope.resumeInfo.wjs}"> <div class="layui-upload-drag upload-area"> <input type="text" style="display:none" name="wjData" value="" class="wjData"/> <input type="text" style="display:none" name="fileName" class="fileName"> </div> </c:forEach> <div class="row resume-submit" style="padding-top:30px;"> <input type="submit" style="float: none" class="button btn-save-next btn-nex" value="上传附件"> </div> </form> <script> function FileUploadFunction(mdata) { if (VailForm(mdata)) { $.ajax({ type: "post", xhrFields: { withCredentials: true }, crossDomain: true, url: "${pageContext.request.contextPath}/resume/saveFile", data: $(mdata).serialize(), success: function (data) { alert(data.info); } }); } return false; } </script>
利用按钮commit出发表单提交,提交时返回false并执行ajax,模拟表单提交上传到后台
相关推荐
ajaxtony 2020-06-11
kentrl 2020-11-10
结束数据方法的参数,该如何定义?-- 集合为自定义实体类中的结合属性,有几个实体类,改变下标就行了。<input id="add" type="button" value="新增visitor&quo
ajaxyan 2020-11-09
zndy0 2020-11-03
学留痕 2020-09-20
Richardxx 2020-11-09
learningever 2020-09-19
chongxiaocheng 2020-08-16
ajaxhe 2020-08-16
lyqdanang 2020-08-16
curiousL 2020-08-03
TONIYH 2020-07-22
时光如瑾雨微凉 2020-07-19
83510998 2020-07-18
坚持着执着 2020-07-16
jiaguoquan00 2020-07-07
李永毅 2020-07-05