首页 > 代码库 > ajax实例2
ajax实例2
前台:
function save() { var username = document.getElementById("username").value; var id = document.getElementById("id").value; var telephone = document.getElementById("telephone").value; var address = document.getElementById("address").value; if(!(/^1[34578]\d{9}$/.test(telephone))){ alert("手机号码有误,请重填"); return false; } $.ajax({ url:"UserAction_modify.do", data:{ "username":username, "telephone":telephone, "id":id, "address":address }, type:"post", dataType:"json", success:function(data){ alert(data.message); }, error:function(data){ alert(data.message); } }); }
后台:
public void modifypsw() throws Exception { JSONObject json = new JSONObject(); HttpServletResponse response = ServletActionContext.getResponse(); HttpServletRequest request = ServletActionContext.getRequest(); String newpsw = request.getParameter("newpsw"); User user = userService.getEntity(id); if(!password.equals(user.getPassword())){ json.put("message", "密码输入错误"); }else{ user.setPassword(newpsw); userService.saveOrUpdateEntity(user); json.put("message", "修改成功"); } try { response.setContentType("text/html;charset=UTF-8"); response.getWriter().print(json.toString()); } catch (IOException e) { e.printStackTrace(); } }
ajax实例2
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。