功能描述:向后台传2个参数,后台取到参数后进行查询,然后返回一个值给前台,再由前台处理
前台代码:
var rightinfo = ""; $.ajax({ url:'<%=path%>/am060402checkRoomIdDup.action', type:'post', //数据发送方式 data: ("newId="+ newId + "&oldId="+ oldId), dataType:'json',//接受数据格式 async: false , success: function(data){ rightinfo = data; } }); //当 rightinfo为“1”时表示当前房间编号没有重复 if(rightinfo == 1){"//此处添加对应处理事件}"} if(rightinfo == 0){"//此处添加对应处理事件"}
后台代码:
public String checkIdDup() throws SQLException, IOException {
ActionContext context = ActionContext.getContext();
HttpServletRequest request = (HttpServletRequest)context.get(ServletActionContext.HTTP_REQUEST);
HttpServletResponse response = (HttpServletResponse)context.get(ServletActionContext.HTTP_RESPONSE);
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
PrintWriter out = getResponse().getWriter();
String oldId= request.getParameter("oldId");
String newId= request.getParameter("newId");
//此处添加:处理对应前台传值过来的查询或者其他操作
if("条件1"){out.print("1")}
if("条件2"){out.print("0")}
out.close();
return null;
}