zoukankan      html  css  js  c++  java
  • ajax小收获

    $.ajax({
    type: "post",
    dataType:"text",
    url: "sugController_toAjax",
    contentType: "application/x-www-form-urlencoded; charset=utf-8",
    data: "index="+i+"&sug_id=${sug.sug_id}&sug_name=${sug.sug_name}&sug_phone=${sug.sug_phone}"+
    "&sug_email=${sug.sug_email}&sug_content=${sug.sug_content}&depart_id=${sug.depart.depart_id}",
    success: function(data){
    alert(data);
    if(data.length!=4){
    //data接过来的是后台的集合
    $("#tab").append(data);
    }
    }
    });

    ajax由于并没有刷新页面 因此不能自动将request域里的信息携带过去 如果需要在前台获取request的新数据 需要在后台手动给request设置值

    public String toAjax() {
    HttpServletRequest request = ServletActionContext.getRequest();
    int object =Integer.parseInt(request.getParameter("index"));
    page.setPageIndex(object);
    Map<String, Object> condMap = new HashMap<>();
    // 往map对象里传递参数
    condMap.put("sug_id", request.getParameter("sug_id"));
    condMap.put("sug_name", request.getParameter("sug_name"));
    condMap.put("sug_phone", request.getParameter("sug_phone"));
    condMap.put("sug_email", request.getParameter("sug_email"));
    condMap.put("sug_content", request.getParameter("sug_content"));
    condMap.put("depart_id", request.getParameter("depart_id"));
    allSug = sugService.getAllSug(condMap, page);
    // 调用本类的方法 返回建议数据
    String html = "";
    if(allSug.size()!=0){
    for (int i = 0; i < allSug.size(); i++) {
    html += "<tr><td>" + allSug.get(i).getSug_name() + "</td><td>"
    + allSug.get(i).getSug_phone() + "</td><td>"
    + allSug.get(i).getSug_email() + "</td><td>"
    + allSug.get(i).getSug_content() + "</td><td>"
    + allSug.get(i).getDepart().getDepart_name() + "</td></tr>";
    }
    }
    else{
    html="没有数据";
    }

    HttpServletResponse response = ServletActionContext.getResponse();
    response.setCharacterEncoding("utf-8");
    PrintWriter out = null;
    try {
    out = response.getWriter();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    out.write(html);
    return null;
    }

    我会因为您的一个点赞而沾沾自喜,但我更会因为您的一次批评而急不可耐,希望你我共同进步
  • 相关阅读:
    设计模式之简单工厂模式
    设计模式之工厂方法模式
    设计模式之抽象工厂模式
    面向对象设计原则
    Spring与Struts整合
    Spring与Hibernate、Mybatis整合
    Java中执行外部命令
    Spring3之Security
    综合练习:词频统计
    组合数据类型综合练习
  • 原文地址:https://www.cnblogs.com/lyaml/p/7660449.html
Copyright © 2011-2022 走看看