Ajax返回的json遍歷取值并顯示到前臺的方法
來源:懂視網
責編:小采
時間:2020-11-27 22:51:26
Ajax返回的json遍歷取值并顯示到前臺的方法
Ajax返回的json遍歷取值并顯示到前臺的方法:使用$.each(data,function(i,n){}); 可以用n.字段,取到想要的值。 $.ajax({ type: 'post', url: '/XXX', dataType: 'json', success:function(data){ var item; $.each(data,function(i,result){ ite
導讀Ajax返回的json遍歷取值并顯示到前臺的方法:使用$.each(data,function(i,n){}); 可以用n.字段,取到想要的值。 $.ajax({ type: 'post', url: '/XXX', dataType: 'json', success:function(data){ var item; $.each(data,function(i,result){ ite

使用$.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>
以上這篇Ajax返回的json遍歷取值并顯示到前臺的方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
Ajax返回的json遍歷取值并顯示到前臺的方法
Ajax返回的json遍歷取值并顯示到前臺的方法:使用$.each(data,function(i,n){}); 可以用n.字段,取到想要的值。 $.ajax({ type: 'post', url: '/XXX', dataType: 'json', success:function(data){ var item; $.each(data,function(i,result){ ite