AJAX方法的应用:
前端页面应用ajax方法向后台方法请求结果,如果结果参数的命名中带有-,则传值不成功。
譬如:
前端Ajax请求方法
$.get("/userhpage/showuserhassesscnt/?user_id="+<%=user_id()%>, function(data) {
?if(data.flag=="1") {
??$("#bestval").html(data.mark_best);
??$("#goodval").html(data.mark_good);
??$("#worseval").html(data.mark-worse);
?}
}, "json");
后台java方法
????? JsonUtil util = new JsonUtil();
??????? try
??????? {
??????????? Map<String, String> map = serviceFactory.getUserHService().getUserhAssessCnt(Integer.valueOf(userId_look));
??????????? util.put("flag", 1);
??????????? util.put("mark_best", map.get("mark-best"));// 好评
??????????? util.put("mark_good", map.get("mark-good"));// 中评
??????????? util.put("mark-worse", map.get("mark-worse"));// 差评
??????? }
??????? catch(Exception e)
??????? {
??????????? util.put("flag", -1);
??????????? logger.error(e.getMessage());
??????? }
??????? response.setCharacterEncoding("UTF-8");
??????? response.getWriter().print(util.toString());
?
注意第三个返回值:util.put("mark-worse", map.get("mark-worse"));// 差评
前端页面$("#worseval").html(data.mark-worse);不会接受此值