日期:2014-05-17 浏览次数:20734 次
public class AjaxAction extends ActionSupport{ private User user; private User user2; private String username; @Override public String execute() throws Exception { user = new User(); user.setUsername(username); user.setId(1); user.setPassword("aaaa1"); user2 = new User(); user2.setId(2); user2.setPassword("22222222222"); user2.setUsername("222"); return SUCCESS; } 和get、set方法
<result type="json" name="success"></result>
function clickButton() { var url = "<%=basePath%>ajax/ajax"; var params = { username:$("#name").val() }; $.post(url, params, callbackFun, "json"); } function callbackFun(data) { alert(data); //1 //alert(data.user.id); //2 //alert(data.id+";"+data.username+";"+data.password); //3 }
public class AjaxAction extends ActionSupport implements ModelDriven<User>{ private User user= new User(); @Override public String execute() throws Exception { user.setId(1); user.setPassword("aaaa1"); return SUCCESS; } @Override public User getModel() { return user; } 和get、set方法
function callbackFun(data){ for(var x in data){ if( typeof data[x] == 'object' ){ for(var y in data[x]){ alert(data[x][y]) } }else{ alert(data[x]) } } }