ajax实现文件异步上传并回显文件相关信息功能示例
本文实例讲述了ajax实现文件异步上传并回显文件相关信息功能。分享给大家供大家参考,具体如下:
上传文件的信息
<div class="form-group"> <div class="col-sm-4"> <label class="control-label">应用文件</label> </div> <div class="col-sm-8"> <input type="file" name="appFile" id="appFile"> <input type="submit" value="确认上传" id="subm"> </div>
ajax提交
$("#subm").click(function(){ var formData = new FormData(); formData.append("appFile", document.getElementById("appFile").files[0]); alert("8888888888888888888888888"); $.ajax({ url: '${ctx}/appresources/fileUpload.shtml', type: "POST", data: formData, dataType: "json", contentType: false, processData: false, success: function (data) { alert("上传成功"); $("#versionCode").val(data.versionCode); $("#appVersion").val(data.appVersion); $("#appPackageName").val(data.appPackageName); }, error: function () { alert("上传失败!"); } }); });
后台处理:
@ResponseBody @RequestMapping("fileUpload") public JSONObject fileUpload(MultipartFile appFile,Model model,HttpServletRequest request,HttpServletResponse response) { ServletContext //........................省略 String infos=ApkUtil.getApkInfo(needPath+"source"+File.separator+"apk"+File.separator+fileName); String[] info=infos.split(","); String versionCode=info[0];//版本号 String versionName=info[1];//版本名 String packageName=info[2];//包名 String appName=fileName; AppResourcesFormMap appResourcesFormMap = getFormMap(AppResourcesFormMap.class); appResourcesFormMap.put("appName",fileName); appResourcesFormMap.put("appVersion",versionName); appResourcesFormMap.put("appPackageName",packageName); appResourcesFormMap.put("versionCode", versionCode); System.out.println(appResourcesFormMap); //model.addAttribute("appresources", appResourcesFormMap); JSONObject fromObject = JSONObject.fromObject(appResourcesFormMap); //String string = fromObject.toString(); return fromObject; }
更多关于ajax相关内容感兴趣的读者可查看本站专题:《jquery中Ajax用法总结》、《JavaScript中ajax操作技巧总结》、《PHP+ajax技巧与应用小结》及《asp.net ajax技巧总结专题》
希望本文所述对大家ajax程序设计有所帮助。
相关推荐
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
坚持着执着 2020-07-05