首先
ajax的dataType需要设置为json,
默认的text获取属性值在jquery3.2.1中尝试不成功
获得属性值的方式:
类似数组,键值对的方式
下面例子:
设置dataType为json
//页面加载完之后,直接去发送一个ajax请求,获取分页数据$(function () {$.ajax({url:'${APP_PATH}/emps',data:'pn=1',type:'get',dataType:'json',success:function (result) {console.log(result);//解析json,显示员工数据build_emps_table(result);//解析json,显示分页导航信息build_page_nax(result);}});});
获取属性值:
//构建员工表格function build_emps_table(result) {//清空table表格$("#emps_table tbody").empty();console.log(result['extend']['pageInfo']['list']);var emps = result['extend']['pageInfo']['list'];$.each(emps,function (index,item) {alert(item.empName);})}
成功: