java中ajax使用--传回一个对象

1、struts.xml配置



dealperson\.id,dealperson\.mobile,dealperson\.telephone,dealperson\.address


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;
    }

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);
                }
            }
        });

你可能感兴趣的:(java,web)