jq ajax
注意:如果ajax请求时参数中有中文,哪么get会出现乱码,使用post可解决
1:绑定事件调用ajax
@RequestMapping("/test") public String gettset(HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType("text/plain" + ";charset=UTF-8"); response.setHeader("Pragma", "No-cache"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); response.getWriter().write("aaa"); response.getWriter().flush(); return null; }
如果要传多个数据可用json
data:{"channelType":$('#channelType').val(),"channel":$('#channel').val(),"day":$('#day').val(),"startTime":$('#startTime').val(),"endTime":$('#endTime').val(),"database":$('#database').val()},
使用其它格式返回(@ResponseBody 直接返回body)
@RequestMapping("/update") public @ResponseBody Map<String, String> updateBandwidth(@ModelAttribute SearchBean searchBean) { Map<String, String> map = new HashMap<String, String>(); try { bandwidthService.upBandwidth(searchBean); String jo = bandwidthService.getBandwidth(searchBean); map.put("status", "ok"); map.put("msg", jo); } catch (UpdateDataBasesException e) { logger.error(e.getMessage()); map.put("status", "no"); map.put("msg", "更新数据失败,请到操作记录页重新操作"); } return map; }
前台页面ajax使 dataType:‘json’
3:spring mvc 前台ajax传值给后台,前台传值为数组,数组中为对象
前台
@RequestMapping("/alarmsystemalarmmesupdate") public @ResponseBody String updateAlarmMessage(@RequestBody List<Map> alarmmessage_list) { return null; }
参考:
http://bbs.csdn.net/topics/390123483
http://ljhzzyx.blog.163.com/blog/static/383803122013115114544562/
相关推荐
kentrl 2020-11-10
结束数据方法的参数,该如何定义?-- 集合为自定义实体类中的结合属性,有几个实体类,改变下标就行了。<input id="add" type="button" value="新增visitor&quo
ajaxyan 2020-11-09
zndy0 2020-11-03
学留痕 2020-09-20
Richardxx 2020-11-09
learningever 2020-09-19
chongxiaocheng 2020-08-16
ajaxhe 2020-08-16
lyqdanang 2020-08-16
curiousL 2020-08-03
TONIYH 2020-07-22
时光如瑾雨微凉 2020-07-19
83510998 2020-07-18
坚持着执着 2020-07-16
jiaguoquan00 2020-07-07
李永毅 2020-07-05
坚持着执着 2020-07-05