ajax请求后台返回map类型并如何展示

前台jsp或者ftl文件接收返回结果:

<input type="hidden" name="selectedModelListStr" id="selectedModelListStr" value='${selectedModelListStr}'>

注意:value值用单引号,因为后台返回的结果是json字符串

前台js接收返回结果:

success: function(data){
      var result = jQuery.parseJSON(data);//也可以这么写:JSON.parse(data);
      if(result.isCopied=="true"){
       myAlert1('复制页面成功!');
       setTimeout(function () {
        alertHidden();
          },2000);
       //查询页面
       queryPageListByNameAndCode('');

}

后台返回结果:

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public static Gson gson = new GsonBuilder().enableComplexMapKeySerialization().create();

public String ajaxJson(HttpServletResponse response, Map<String, String> jsonMap) {
  return ajax(response,gson.toJson(jsonMap), "text/html");
 }

/**
  * AJAX输出,返回null
  *
  * @param content
  * @param type
  * @return
  */
 public String ajax(HttpServletResponse response, String content, String type) {
  try {
   response.setContentType(type + ";charset=UTF-8");
   response.setHeader("Pragma", "No-cache");
   response.setHeader("Cache-Control", "no-cache");
   response.setDateHeader("Expires", 0);
   response.getWriter().write(content);
   response.getWriter().flush();
  } catch (IOException e) {
   log.error("IOException:", e);
  }
  return null;
 }

原文地址:https://www.cnblogs.com/nizuimeiabc1/p/7096534.html