在做一个博客的时候遇到的一问题,我后台写好接口,前台ajax调用,代码如下:
<script type="text/javascript">
$(document).ready(function(){
$.ajax({
type: 'get',
url: '/index/listarticle',
dataType: 'json',
success: function(data) {
console.log(data);
}
})
})
</script>
返回的数据是一个二维数组,我怎么把这个二维数组的数据放到html页面当中,我只会一点很粗浅的JS
求大神指教

解决方案 »

  1.   

    <div id="web"></div>
    <script type="text/javascript">
        var html="";
        $(document).ready(function(){
            $.ajax({
                type: 'get',
                url: '/index/listarticle',
                dataType: 'json',
                success: function(data) {
                   for(var i =0;i<data.length;i++){    //循环遍历得到的二维数组
                               html+='<div><p>ID:'+data[i].id+'</p><p>名称:'+data[i].name+'</p></div>'  ;//假如有字段Id,name
                      }
                   $("#web").html(html);//赋值到id=web的DIV中
                }
            })
        })
    </script>
      

  2.   

    append    before     after
      

  3.   

    使用jq 或者 js 操作页面dom即可
      

  4.   

    append()    text()   html()     val()          before()      after()
      

  5.   

    一般是2楼的套路,返回的是json数组,遍历组装html,然后用7楼的函数显示在网页。