Ajax请求接口并将数据返回到页面
生活随笔
收集整理的這篇文章主要介紹了
Ajax请求接口并将数据返回到页面
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
<script>$(function(){$.ajax({type: "post",//接口地址url: "http://47.92.145.141:8111/index/index/newsList",data: {},dataType: "json",//成功后返回的數(shù)據(jù)success: function(data){console.log(data,"datadata")var html = ''; //拼接數(shù)據(jù)$.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>
總結(jié)
以上是生活随笔為你收集整理的Ajax请求接口并将数据返回到页面的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 新手做外汇保证金交易的思路
- 下一篇: 区块链共识算法之BFT(4)