目标: 我有一个按钮,该按钮运行一个函数以从Mongoose数据库中加载更多项并将其添加到表行中。我使用get从服务器端获取和返回数据。并且正在遵循this post的指针,但是我仍然无法呈现所需的内容。
客户端代码:
<main role="main">
<div class="container-fluid ">
<div class="card-columns" id="test" value="<%=deals%>">
<tbody>
<tr id="content"><% include partials/row.html %></tr>
</tbody>
</div>
</div>
<div class="container" style="max-width: 25rem; text-align: center;">
<a id="8-reload" class="btn more" onclick="loadmore(8)"></a>
</div>
<script >
const loadmore = async function(x){
const response = await fetch(`/${x}`);
if (!response.ok)
throw oops;
const data =await response.text();
console.log(data);
console.log($("#content"));
await document.getElementById('content').insertAdjacentHTML('beforeend',data);
}
</script>
服务器JS请求:
app.get(`/:count`,(req,res) => {
const count = parseInt(req.params.count);
database.find({},(err,found) => {
if (!err){
res.render("more",{items:found},html)=>{
if(!err){
res.send(html);
}else{
console.log(err);
}
});
} else {
console.log(err);
}
}).skip(count).limit(25);
});
当运行该功能时,什么也没有发生,并且浏览器控制台日志读取html的长字符串。这是我要附加的位置:
jQuery.fn.init {} 原始:对象(0)
服务器控制台日志上没有错误。我想念什么?
更新我尝试了“添加”而不是内容来测试和发现我正在添加html,但不是全部内容。 int仅插入整个html模板的开始和结束,而其间没有任何内容。奇怪的。