功能描述:向后台传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;
}

本文介绍了一个简单的前后台交互示例,前台使用Ajax向后台发送请求并接收返回值,后台通过查询处理请求并返回结果。
 示例①&spm=1001.2101.3001.5002&articleId=84363760&d=1&t=3&u=9b20a30c81584cbfb1be873a29b0efca)
4831

被折叠的 条评论
为什么被折叠?



