如何將ajax請求返回的Json格式數(shù)據(jù)循環(huán)輸出成table形式
更新時間:2013年10月29日 15:11:47 作者:
ajax請求返回Json格式數(shù)據(jù),在網(wǎng)上有很多的處理方法,本文教大家如何循環(huán)輸出成table形式,代碼很詳細,感興趣的朋友可以參考下
首先,Ajax請求數(shù)據(jù),(用的是Jquery的Ajax)
<script>
$(function(){
$('#test').click(function(){
$.ajax({
url:'__APP__/Article/jsonTest',
type:'post',
success:function(data){
var item;
$.each(data,function(i,result){
item = "<tr><td>"+result['num']+"</td><td>"+result['title']+"</td><td>"+result['credate']+"</td><td>操作</td></tr>";
$('.table').append(item);
});
}
})
})
});
</script>
后臺處理請求,返回Json格式數(shù)據(jù)(用的是Thinkphp返回)
$list = $File->group('num')->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
$this->ajaxReturn($list,'JSON');
html部分
<table class="table table-striped table-bordered table-condensed">
<tr><th>編號</th><th>名稱</th><th>創(chuàng)建時間</th><th>操作</th></tr>
</table>
效果如圖
OK
復(fù)制代碼 代碼如下:
<script>
$(function(){
$('#test').click(function(){
$.ajax({
url:'__APP__/Article/jsonTest',
type:'post',
success:function(data){
var item;
$.each(data,function(i,result){
item = "<tr><td>"+result['num']+"</td><td>"+result['title']+"</td><td>"+result['credate']+"</td><td>操作</td></tr>";
$('.table').append(item);
});
}
})
})
});
</script>
后臺處理請求,返回Json格式數(shù)據(jù)(用的是Thinkphp返回)
復(fù)制代碼 代碼如下:
$list = $File->group('num')->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
$this->ajaxReturn($list,'JSON');
html部分
復(fù)制代碼 代碼如下:
<table class="table table-striped table-bordered table-condensed">
<tr><th>編號</th><th>名稱</th><th>創(chuàng)建時間</th><th>操作</th></tr>
</table>
效果如圖
OK
相關(guān)文章
Ajax跨域查詢完美解決通過$.getJSON()實現(xiàn)
瀏覽器安全上做了限制,禁止ajax跨域獲得數(shù)據(jù),可以通過jquery提供的$.getJSON()可以跨域獲得JSON格式的數(shù)據(jù),具體的實現(xiàn)如下,感興趣的朋友可以參考下哈,希望對大家有所幫助2013-06-06
AJAX下的請求方式以及同步異步的區(qū)別小結(jié)
AJAX中的請求方式以及同步異步的區(qū)別小結(jié),學(xué)習(xí)ajax處理請求的朋友可以參考下。2010-08-08
Ajax實現(xiàn)動態(tài)顯示并操作表信息的方法
今天小編就為大家分享一篇Ajax實現(xiàn)動態(tài)顯示并操作表信息的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08

