项目过程中偶然用到异步提交FORM,然后返回一个结果提示信息,
@RequestMapping("/saveBatchAsyn")
@ResponseBody
public Map<String,String> saveBatchAsyn(***,,HttpServletResponse response) throws IOException {****}
在FF下没问题,在IE下提示下载文件,看日志操作成功了,只是返回信息没有识别,提示下载文件,
搞了N久,也在网上查了N多资料,但是都语焉不详,
自己试了很多遍,终于搞掂了,
解决方法如下:
1、接口返回值修改,
public void saveBatchAsyn(***,,HttpServletResponse response) throws IOException {****}
2、接口实现内部修改
Map<String,String> retMap = new HashMap<String,String>();
retMap.put("flag", flag);
retMap.put("msg", msg);
PrintWriter out = response.getWriter();
out.write(net.sf.json.JSONObject.fromObject(retMap).toString());//此处如果返回一个List,需要用net.sf.json.JSONArray.fromObject().toString()
out.flush();
out.close();
3、前端页面调整
成功的回调函数提示:
success:function(data){
var data = $.parseJSON(data); // change the JSON string to javascript object
$.messager.alert("结果提示",data.msg,"info");
}