慕仔8415870
2021-08-21 15:01
const fs = require('fs')
var data = fs.readFileSync('./data/list.json')
data = JSON.parse(data)
var list = data.splice(body.page * body.count,body.count)
ctx.body = {
errcode:0,
errmsg:'ok',
list
}
// ctx.body = 'ok'
})
js数据
<script id="tpl-sportsList" type="text/html">
{{each list}}
<li>
<div class="sports-list-text">
<p>
{{$value.title}}
</p>
<p>
<span>{{$value.comment}}评</span>
</p>
</div>
<div class="sports-list-img">
<img src="{{$value.img}}" alt=""/>
</div>
</li>
{{/each}}
</script>
<script>
var sportsList = document.querySelector('.sports-list')
var xhr = new XMLHttpRequest()
xhr.onload = function(){
if(xhr.status == 200){
// console.log(xhr.responseText)
var data = JSON.parse(xhr.responseText)
if(data.errcode == 0){
sportsList.innerHTML = template('tpl-sportsList',data)
}
}
}
xhr.open('POST','/index',true)
xhr.setRequestHeader('Content-Type','application/json')
xhr.send(JSON.stringify({"page" : 0,"count" : 10}))
</script>
这个地方有问题,运行时,弹出2,具体怎么解决还不清楚
if(xhr.status == 200){
alert(1)
}else{
alert(2)
}
Ajax实战案例之列表渲染
8343 学习 · 34 问题
相似问题