小型网站不使用vue框架如何实现数据渲染到前端页面

1,先写ajax请求

eg:

<script src="jquery.min.js"></script>
<script>
   $(function(){
       var xhrul='http://192.168.31.133:3000/jdapi';
       $.ajax({
          type:'get',
           async:false,
           url:xhrul,
           cache:false,
           dataType:"jsonp",
           success:function(json){
              console.log(json);
           },
           err:function(e){
               alert("error")
           }
       })
   })
</script>

2,在success里写数据绑定(只是示例,不全)

success:function(json){
   console.log(json);
   var html=''; //定义变量
   $("#climit li").html(""); //选中标签
   $(json.categorys).each(function(i,categorys){  //json.categorys的categorys是数据咯的最外面那个数组,each循环遍历
       html+='<li class="relative">......</li>(html内容)';
       html+='<p>......</p>';
       $(categorys.categoryItems).each(function(i,categoryItems){
           html+='';
       })
   })
},

采用对象的形式取值

猜你喜欢

转载自blog.csdn.net/L_AMiao/article/details/83049397