jquery循环显示api接口的数据

 $(window).load(function(){
        $.ajax({
        url:"/index/product/hotpro",
        method:"post",
        dataType: "json",
        success:function (json) {
            console.log(json);
                var html = '';
                //拼接数据
                $.each(json.data, function(commentIndex, comment){
                    html += '<div class="gallery-block masonry-item all col-lg-4 col-md-6 col-sm-12"><div class="inner-box"><div class="image"><a href="detail?id='+comment['id']+'"><img src='+comment['thumb']+' alt=""></a><h4 style=" text-align:center; line-height: 40px;">'+comment['title']+'</h4></div> </div> </div>';

                });

                $('#product_all').html(html);
            }
        });
    });

  

原文地址:https://www.cnblogs.com/web928943/p/13839888.html