ajax请求返回json数据弹出下载框的解决方法

时间:2023-03-08 18:30:15
ajax请求返回json数据弹出下载框的解决方法

将返回的Content-Type由application/json改为text/html。

在struts2下:

<action name="XXXAjax" class="XXXAction">
<result type="json">
<param name="contentType">text/html</param>
</result>
</action>

在spring3.x mvc下:

HttpHeaders headers = new HttpHeaders();
MediaType mt=new MediaType("text","html",Charset.forName("UTF-8"));
headers.setContentType(mt);
ResponseEntity<JsonModel> re=null;
re=new ResponseEntity<JsonModel>(jsonModel,headers, HttpStatus.OK);
return re;