mysql - 无法将数据从 express 传递到 ejs?
问题描述
res.send("filename.ejs",data
我尝试将数据从 js 文件(sample.js)传递给ejs
TypeError:无法在字符串上创建属性“_locals”
有人可以帮助解决这个问题并告诉我如何在 ejs 文件中调用它们
解决方案
res.send() 用于发送数据不需要指向 ejs 文件
res.send 将数组作为参数 (res.send([body])) ,您可以在 ejs 中获取它,例如 {{ data }}
例如
NODEJS res.send({message: 'hello'})
文件名.ejs
<div>{{ message }}</div> or <%= JSON.stringify(message) %>
也因为 Express 5x 不支持res.send()
您可以使用的方法
res.status(200).send({message: 'hello})
(你不承认你是快递版)
推荐阅读
- jquery - 使用jquery获取一组元名称中的较大数字
- datetime - 在SAS范围内满足特定条件时删除行
- svg - Pixi.JS 虚线(或虚线)贝塞尔曲线
- java - 在 IntelliJ 中创建评论 @return 和 @param 的快捷方式是什么?
- python - 从初始值开始的数字的累积差
- python - 如何读取列由双引号和空格分隔的csv文件
- javascript - 无法在 React 应用程序的 Date 中正确减少天数
- c# - C# 脚本在不应该被评估的脚本上部分失败
- swift - Xcode 13 自动构建问题(索引)
- kubernetes - 带有内部负载平衡器的 Google Identity Aware 代理