后台返回值:"{'status':success,'path': }";
页面的sucess: function(data)中的data的值如图
当然我的dataType: 'json'
@ResponseBody
@RequestMapping(method = RequestMethod.POST, value = "/upload")
public void upload(@RequestParam("myfiles") MultipartFile myfiles, HttpServletRequest request,
HttpServletResponse response) throws IOException{
String filePath = UploadFile.uploadImage(Constants.ENTERPRISE_LOGO_FTP_FILE_PATH, myfiles);
DecimalFormat df = new DecimalFormat("0.00");
Double d = (myfiles.getSize())/(1024.0);
String fileSize =df.format(d);
String result = "{'status':'"+ Constants.RETURN_STATUS_SUCCESS + "','path':'" + filePath + "','fileSize':'" + fileSize + "'}";
response.setContentType("text/json");
ServletOutputStream outputStream = response.getOutputStream();
outputStream.write(result.getBytes());
outputStream.flush();
}
$.ajaxFileUpload({
url:'${ctx}/CorpAttachmentController/upload',
secureuri:false,
fileElementId: fileId,
dataType: 'json' ,
success: function (data){
alert("上传!"+data);
},error: function (data){
alert("上传失败!"+data);
} });