$.ajax({
url:"<%=request.getContextPath()%>/login_update.action",
type:"post",
data:{
id:id,
name:name,
email:email
},
dataType:"json",
success:function(obj){
if(obj){
alert("修改成功!");
location.href = "<%=request.getContextPath()%>/login_toList.action;
}
else{
alert("修改失败!");
}
}
}) 前台ajax
后台接收public String update() throws SQLException {
//通过ID找对象
UserInfo userInfo = UserInfoDataProvider.getInstance().getUserInfoById(id);
System.out.println("==============================================================="+userInfo.getName());
//更新
UserInfoDataProvider.getInstance().updateUserInfo(userInfo);
HttpServletResponse response = ServletActionContext.getResponse();
JSONObject json = JSONObject.fromObject(userInfo);
try {
response.getWriter().write(json.toString());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
} ,接收到的name不是我要更新的,还是原来的,我的那个json数组写的是否正确?
你用的id,name两个参数,你还没有解析出来呢?而你的返回值是null
你data里面
key值加引号
value值没有获取到
你这个data:{
id:id,
name:name,
email:email
}, :后面的值name,email,id是啥