附加提取的ejs项

目标: 我有一个按钮,该按钮运行一个函数以从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模板的开始和结束,而其间没有任何内容。奇怪的。

cjwannafly 回答:附加提取的ejs项

好吧,似乎最大的问题是两件事。第一个问题是我要附加到内容无法附加的位置。第二个问题是“我的模板”从“表”行开始,其中包含更多内容,不允许其他内容呈现。一旦我将jquery移到一个父ID并删除了表行,一切就一切正常了!

本文链接:https://www.f2er.com/3107729.html

大家都在问