springboot升级到1.5.10以上时ajaxSubmit请求返回失败

项目的springboot从1.5.10升级到1.5.16,发现老代码里ajaxSubmit的请求返回都为error了.

后台接口收到请求并正常处理和返回,没有任何异常。但前端接受到的返回体是个空对象。

前端请求代码:

<form id="uploadForm" action="/image/upload" method="post"  enctype="multipart/form-data">
<input type="file" id="imageFile" name="imageFile" accept=".jpg,.jpeg,.png,.gif">
</form>
$("#uploadForm").ajaxSubmit({
	success: function (data) {
		alert("上传照片成功!");
	},
	error: function (data) {
		alert("上传失败");
	}

后端接收代码:

@RequestMapping(value = "/upload", method = RequestMethod.POST)
public void upload(@RequestParam(value = "imageFile", required = false) MultipartFile imageFile,HttpServletResponse response){
    imageService.saveUploadImage(imageFile);
PrintWriter out = null;
        try {
            response.setContentType("text/html; charset=utf-8");
            response.setHeader("Cache-Control", "no-cache");
            response.setHeader("X-Frame-Options", "SAMEORIGIN");
            out = response.getWriter();
            out.write("success");
            out.flush();
        } catch (Exception ex) {
            throw new RuntimeException("write return string has error", ex);
        } finally {
            if (out != null)
                out.close();
        }
}

js返回内容(data):

接口返回头:

后将ajaxSubmit重写为ajax请求解决。

测试发现从1.5.11开始都会出现此问题。

猜测应该是与springboot安全相关的默认配置有关,因ajaxSubmit的实现原理是创建iframe来发送请求和接受返回

预计相关包:

org.springframework.boot:spring-boot-starter-web
org.springframework.boot:spring-boot-starter-security
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值