<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>数据获取和模板渲染</title>
<script src="https://unpkg.com/art-template@4.13.2/lib/template-web.js"></script>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<ul id="postsBox">
</ul>
<script type="text/html" id="pageTpl">
{{each data}}
<li>{{$value.label}}</li>
{{/each}}
</script>
<script>
$.ajax({
type: 'get',
url: 'http://localhost:8080/area/hot',
success: function (response) {
// console.log(data)
var html = template('pageTpl', {data:response.body});
console.log(html)
$('#postsBox').html(html);
}
});
</script>
</body>
</html>
ajax和art-template模板的基本使用
最新推荐文章于 2021-09-23 11:29:35 发布