zoukankan      html  css  js  c++  java
  • 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;
     }

  • 相关阅读:
    (Problem 4)Largest palindrome product
    (Problem 3)Largest prime factor
    (Problem 2)Even Fibonacci numbers
    (Problem 1)Multiples of 3 and 5
    Ural 1086
    Ural 1319
    Ural 1149
    Ural 1079
    Ural 1068
    2016/04/06
  • 原文地址:https://www.cnblogs.com/nizuimeiabc1/p/7096534.html
Copyright © 2011-2022 走看看