码迷,mamicode.com
首页 > Web开发 > 详细

ajax小收获

时间:2017-10-13 14:03:27      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:ted   amp   建议   trace   art   不能   param   parse   public   

$.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;
}

ajax小收获

标签:ted   amp   建议   trace   art   不能   param   parse   public   

原文地址:http://www.cnblogs.com/lyaml/p/7660449.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!