javascript - 我如何使用 json 而不是 jade 发送响应?

标签 javascript json node.js express

//这是我的index.js文件

var express = require('express');
var router = express.Router();

/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Movie Database' });
});

module.exports = router;

//这是我的index.jade文件

extends layout

block content
  h1= title
  p Welcome to #{title}

最后,我想使用 json 做同样的事情。

最佳答案

只需使用res.send(/*你的json*/);。喜欢:

res.send({ title: '...' });

请参阅docs .

关于javascript - 我如何使用 json 而不是 jade 发送响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34370578/

相关文章:

javascript - Heroku 本地持久存储

javascript - 将 onRowClick 绑定(bind)到 DoJo 数据网格 (dojox.grid.DataGrid)

javascript - jquery 链接在下一页加载之前单击切换图像

PHP JSON 无法正确解码

javascript - Puppeteer:从使用延迟加载的页面中抓取整个 html

node.js - 如何使用嵌套模式更新 mongodb 中的文档

javascript - 我如何访问这个 json 中的内容?

javascript - 将 onClick 传递给导入的组件,使用react

javascript - 如何从 JavaScript 对象呈现 HTML 中的嵌套列表?

ajax - jquery mobile可折叠和galaxy tab 10.1 json响应给出随机响应