【问题标题】:Partial View - Get html that would be render部分视图 - 获取将要呈现的 html
【发布时间】:2016-10-26 03:39:22
【问题描述】:

背景: 我在发送 html 的路由文件夹中创建了一个 GET 请求。它将用于 ajax 请求:

router.get(url, function(){
  res.send("<p>Some Text</p>");
}) 

我的想法/疑问/问题如下,是否可以使用部分视图来生成我想要的html并发送它?

我有我需要的代码的部分视图,它在主渲染中使用,在两个不同的部分中编辑代码令人沮丧。

【问题讨论】:

  • 你可以发布你想使用的局部视图吗?
  • 先生,我已经找到路了。您可以在下面查看答案。

标签: javascript ajax node.js express ejs


【解决方案1】:

我找到了方法:

res.render(view, function(err, html){
  if(!err){
    res.send(html);
  }
});

如果使用回调函数,则取消默认的页面渲染行为。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-10-18
    • 1970-01-01
    • 1970-01-01
    • 2013-06-17
    • 1970-01-01
    • 1970-01-01
    • 2013-04-09
    相关资源
    最近更新 更多