JQuery中Ajax使用

来源:互联网 发布:淘宝九块九包邮网址 编辑:程序博客网 时间:2024/06/05 21:14

http://blog.csdn.net/zhanghong0603/article/details/51851219

1、struts.xml配置 
<!-- 查询人员信息 --> 
<action name="validateDealper" class="sealBusinessAction" method="validateDealper"> 
<result type="json"> 
<param name="includeProperties">dealperson\.id,dealperson\.mobile,dealperson\.telephone,dealperson\.address</param> 
</result> 
</action>
 
2、action

// 判断办理人是否已存在    public String validateDealper() {        String dealper = getRequest().getParameter("dealper");        String dealpercode = getRequest().getParameter("dealpercode");        this.dealperson = this.sealbusinessService.Getdealperson(dealper,                dealpercode);        return SUCCESS;    }private String jsonResultMsg = null;public String getJsonResultMsg() {        return jsonResultMsg;    }    public void setJsonResultMsg(String jsonResultMsg) {        this.jsonResultMsg = jsonResultMsg;    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

3、js 
var dealperson = msg.dealperson;获得后台查询的对象。

$.ajax( {            type : "post",            url : "validateDealper.action",            dataType : "json",            data : {"dealper":getper,"dealpercode":code},            async : false,            cache : false,            success : function(msg) {                var dealperson = msg.dealperson;                if (dealperson != null) {                    var id = dealperson.id;                    var mobile = dealperson.mobile;                    var telephone = dealperson.telephone;                    var address = dealperson.address;                    $("#dealpersonid").val(id);                    $("#mobile").val(mobile);                    $("#telephone").val(telephone);                    $("#address").val(address);                }            }        });

原创粉丝点击