使用json传递参数

阅读更多

后台代码:

@ParentPackage("json-default")
@Namespace("../zoneAjaxAction")
public class ZoneAjaxAction extends ActionSupport {
    private static final long serialVersionUID = 3540620102073531681L;
    private static Logger log = Logger.getLogger(ZoneAjaxAction.class);
    //注入
    @Resource(name="RegisterService")
    private RegisterService registerService;
    @Resource(name="GlobalVariableService")
    private GlobalVariableService globalVariableService;
    //--------------页面表单参数
    //cityId||cityName
    private String cityId;
    private String cityName;
    private List zoneList ; //列表
    private String zoneType;//类型
     @Action(value="showZoneList",results={
            @Result(type="json")})                   
    public String showZoneList(){     
        //根据名称来获取列表
        zoneList = registerService.getZoneList(cityName, cityId, globalVariableService.get("SysCode").getValue(),zoneType);
        //带有分中心标识过滤
        return SUCCESS;
    }
   
    //---------------------------------------set/get
    public void setRegisterService(RegisterService registerService) {
        this.registerService = registerService;
    }
    @JSON(name="cityId")
    public String getCityId() {
        return cityId;
    }
    public void setCityId(String cityId) {
        this.cityId = cityId;
    }
    @JSON(name="cityName")
    public String getCityName() {
        return cityName;
    }
    public void setCityName(String cityName) {
        this.cityName = cityName;
    }
    @JSON(name="zoneList")
    public List getZoneList() {
        return zoneList;
    }
    public void setZoneList(List zoneList) {
        this.zoneList = zoneList;
    }
    @JSON(name="zoneType")
    public String getZoneType() {
        return zoneType;
    }
    public void setZoneType(String zoneType) {
        this.zoneType = zoneType;
    }
}

 页面js方法:

function showZoneListSelect(obj,zoneType,targetId){
    var cityName = $("#administrativeDivisionLeve2 option:selected").text();
    //alert(cityName);
    var cityId = $(obj).val();
    //alert(cityId);
    //alert(parentCityId + "\t" + cityLevel);
    $.getJSON("<%=basePath %>/sys/userReg/zoneAjaxAction/showZoneList.action",{"cityName":cityName,"cityId": cityId ,"zoneType":zoneType}, function(json){
        options="";
        $.each(json.zoneList,function(i){
            options+="";
            });
        //alert(options);
        $("#" + targetId).html(options);
    });
}

 

你可能感兴趣的:(json,传递参数)