关于ajax返回数据获取问题

本文详细探讨了一个关于前后端数据交互的问题,即在使用$.ajax进行异步请求时,如何正确解析从Java后台返回的JSON数据。具体地,尽管能成功获取到priceId,但在尝试访问priceMoney字段时却遇到undefined错误。文章深入分析了这一现象的原因,并提供了有效的解决方案。

直接先贴代码

$.ajax({
        type:'post', 
        dataType: "json",
        url:url,
        contentType: 'application/json;charset=utf-8',
        data:JSON.stringify(datas),
        success: function(result){
            alert(result[0].priceId);
            alert(result[0].pricemoney);
            $.each(result, function(index, item){
                findTableQuery += '<tr>'+
                                    '<td>'+item.goods.goodsname+'</td>'+
                                    '<td>'+item.pricemoney+'</td>'+
                                    '<td>'+item.date+'</td>'+
                                  '</tr>'
            });
            //清空上次数据
            $("#tableQuery tBody tr:not(:first)").html("");
            //插入新查询数据
            $("#tableQuery #trQuyer").after(findTableQuery);
        }

后台代码

    @RequestMapping(value="/recordQuery")
    @ResponseBody
    public List<Price> getPriceList(@RequestBody String[] array){
        int areaId = Integer.parseInt(array[0]);
        String goodsName = array[1];
        //查询物品是否存在
        Goods goods = this.goodsService.getGoodsBy(goodsName);
        //查询物品记录
        List<Price> priceList = this.priceService.getPriceByList(areaId,goods.getGoodsId());
        for(Price price : priceList){
            System.out.println(price.getArea().getAreaName()+"-"+
                               price.getGoods().getGoodsName()+"-"+
                               price.getPriceMoney()+"-"+price.getDate());
        }
        return priceList;
    }

以下是调试js时查看到result的返回数据

Array(2)
0:{priceId: 1, priceMoney: "3246", date: 1534464000000, areaId: null, goodsId: null, …}
1:{priceId: 2, priceMoney: "3084", date: 1534550400000, areaId: null, goodsId: null, …}
length:2
__proto__:Array(0)

我的问题就是,为什么我获取到priceId是没有问题的,但获取priceMoney得到的确是undefined。
有没有大佬可以告诉我这该怎么解决,百度了老半天,各种五花八门的方法都用遍了,结果还是这样。

每次出问题,在CSDN上询问,都是石沉大海,难道CSDN已经无人了?我一个人在玩单机?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值