Ajax請求接口並將數據返回到頁面

  <script>

$(function(){
 
  
         
         $.ajax({
 
             type: "post",
             //接口地址
            url: "http://47.92.145.141:8111/index/index/newsList",
 
           data: {},
 
             dataType: "json",
             //成功後返回的數據
             success: function(data){
 
                      
                          console.log(data,"datadata")
                          var html = ''; 
                          //拼接數據
                         $.each(data.data, function(commentIndex, comment){
                               html += 
                               '<div class="context-1"><div class="left"> <img src="http://47.92.145.141:8111'+comment["image"]+'" alt=""></div> <p class="p1">'+comment["title"]+'</p><p class="p2">'+comment["message"]+'</p><p class="p3">'+comment["add_time"]+'</p><div class="right"><a href="newsdetails.html?id='+comment["id"]+'">查看詳情</a></div></div>'; 
 
                         });
 
                         $('#resText').html(html);
 
                      }
 
         });
 

 
})();
    </script>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章