标签:function ajax win oca ada window type adapter .com
1、配置文件 /wbh-adapter-h5/src/main/resources/dispatcher-servlet.xml
<!-- 文件上传需要配置该句 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />
2、jquery.form 提交表单;
$(function(){ //异步提交表单 $("#ajaxSubmit").on("click",function(){ console.log($(this)); $("#uploadForm").ajaxSubmit({ type:‘post‘, url:‘${context}/mobile/uploadimgs‘, success:function(data){ console.log(data); var data= eval(data); if(data.errorCode=="1"){ $.alert(data.errorMessage); }else{ $.showPreloader(‘编辑成功...‘); setTimeout(function () { $.hidePreloader(); window.location.href=‘${context}/weish/index‘; }, 2000); } }, error:function(XmlHttpRequest,textStatus,errorThrown){ console.log(XmlHttpRequest); console.log(textStatus); console.log(errorThrown); $.showPreloader(‘服务器异常,请重试...‘); } }); }); });
后台:
/** * 上传用户图片,通用 * * @param res 传过来的资源对象 * @return 目标对象 * @throws Exception */ @RequestMapping(value = "/mobile/uploadimgs", method = RequestMethod.POST) public @ResponseBody JsonResult uploadimgs( HttpServletRequest request, HttpServletResponse response, com.wbh.adapter.bean.out.user.UserImg userImg, @RequestParam(value = "fieldName", required = false) MultipartFile file) { JsonResult result = new JsonResult(); try { result = usersService.uploadImgs(userImg, file); } catch (MalformedURLException e) { e.printStackTrace(); } return result; }
标签:function ajax win oca ada window type adapter .com
原文地址:http://www.cnblogs.com/hoge/p/6413597.html