码迷,mamicode.com
首页 > Web开发 > 详细

ajax实例2

时间:2016-12-14 14:02:30      阅读:352      评论:0      收藏:0      [点我收藏+]

标签:data   ret   action   try   phone   update   后台   throws   密码   

前台:

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

标签:data   ret   action   try   phone   update   后台   throws   密码   

原文地址:http://www.cnblogs.com/Crysta1/p/6178759.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!