首先
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); }) }
成功: