标签:
1. 前台向后台传值
提交form表单
<form id="sb" action="${pageContext.request.contextPath }/admin/loanContract/addOrUpdate.do" method="post"> 各种输入框各种值 <button class="tjbtn" id="sbm">提 交</button></form>
用form提交有个问题就是:提交到后台后,成功后,后台跳转页面只能跳到响应的页面了,但是想要保留在本页面并且弹出alert,就只能这种方法,应该加上@ResponseBody
@RequestMapping("updateSelfdomNeed")
@ResponseBody public void updateSelfdomNeed(HttpServletRequest request,HttpServletResponse response){ String textArea = request.getParameter("textArea"); String wishId = request.getParameter("wishId"); int count = selfdomNeedService.updateSelfNeed(wishId,textArea); response.setContentType("text/html;charset=utf-8"); PrintWriter out = null; try { out = response.getWriter(); if(count>0){ out.print("<script>alert(‘处理成功!‘);" + "location.href=‘/CarExchange/admin/selfdomNeed/selfdomNeedList.do‘;</script> "); } else{ out.print("<script>alert(‘处理失败!‘);location.href=‘/CarExchange/admin/selfdomNeed/selfdomNeedList.do‘;</script> "); out.close(); } } catch (IOException e) { e.printStackTrace(); } }
js中用ajax
$("#sbm").click(function(){ var sp = $("#sp").html(); if(sp!=‘交易订单已存在!‘){ $("#sb").submit(); return; } alert(‘交易订单已存在或为空!‘); return; }); $("#tradeCode").blur(function(){ var tradeCode = $("#tradeCode").val(); $.ajax({ url:"checkTradeCode.do", data:{tradeCode:tradeCode}, dataType:"json", success:function(data){ var arr = eval(data); $("#sp").html(arr.code); } }); });
2.
标签:
原文地址:http://www.cnblogs.com/weixiaole/p/4774214.html