日期:2014-05-16  浏览次数:20690 次

jquery使用ajax。action返回的json为null 求高手解决。
贴出代码

jquery代码
HTML code
<script type="text/javascript">
$(document).ready(function(){
    $("#district_id").change(function(){
        var district_id=$("#district_id").val();
        //alert(district_id);
        $.post("streetList.action",{districtId:district_id},function callBack(data){
            var bb=eval("("+data+")");
             alert(bb);
        },'json');
    });
});
</script>




struts。xml代码
XML code
<package name="default" extends="json-default">
<action name="streetList" class="com.accp.houserent.action.HouseAction"
            method="streetList">
            <result type="json"><param name="root">result</param></result>
        </action>
</package>


action代码
Java code
/**
     * 获得街道列表
     */
    public String streetList() throws Exception {
        // TODO Auto-generated method stub
        HttpServletRequest request = getHttpServletRequest();
        
        try {
            CommonBiz commonBiz = new CommonBizImpl();
            String districtId = request.getParameter("districtId");
            District district = commonBiz.getEntity(District.class,
                    Integer.parseInt(districtId));
            // System.out.println(district.getStreets().size());
            Map<String, Street> map = new HashMap<String, Street>();
            Iterator<Street> it = district.getStreets().iterator();
            while (it.hasNext()) {
                Street street = it.next();
                map.put(street.getStreetName(), street);
            }
            result =map;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return SUCCESS;
    }
    private Map<String, Street> result;

    public Map<String, Street> getStreets() {
        return result;
    }

    public void setStreets(Map<String, Street> result) {
        this.result = result;
    }


问题出现 0 0.。。为什么jquery 弹窗一直都是null。。
求解释。。第一次用jquery和json是不是在配置上面有关系。?

------解决方案--------------------
$.post("streetList.action",{districtId:district_id},function callBack(data){
alert(data);
},'text');
改成这样。看弹出的是什么
------解决方案--------------------
'json'是返回的格式,你返回的是json格式吗?》