1. 程式人生 > >spring mvc3使用jquery easyui form提交返回值提示下載的問題

spring mvc3使用jquery easyui form提交返回值提示下載的問題

專案過程中偶然用到非同步提交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");
                   }