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 Boot → 08:嵌入式Servlet容器自定义
    Spring Boot → 09:使用外置Servlet容器_tomcat9.0
    Spring Boot → 07:错误处理机制
    Spring Boot → 06:项目实战-账单管理系统
    Spring Boot → 05:Web开发
    zzz Objective-C的消息传递机制
    Objective-C中的SEL、IMP和Class类型(转)
    zzzObjective-C的动态特性
    zzz KVC/KVO原理详解及编程指南
    zzzzz iOS绘图教程
  • 原文地址:https://www.cnblogs.com/lyaml/p/7660449.html
Copyright © 2011-2022 走看看