Ajax返回的json遍历取值并显示到前台的方法
时间:2021-05-01 09:34:15|栏目:JavaScript代码|点击: 次
使用$.each(data,function(i,n){});
可以用n.字段,取到想要的值。
$.ajax({
type: 'post',
url: '/XXX',
dataType: 'json',
success:function(data){
var item;
$.each(data,function(i,result){
item=
"<tr><td>"+result['name']+"</td><td>"+result['age']+"</td></tr>";
$('.table').append(item);
});
},
});
然后将item打入table里
<table class="table"> <tr><th>name</th><th>age</th></tr> </table>






