![](/img/trans.png)
[英]How can I transfer an image from html to nodejs to use it with ejs?
[英]NodeJS use EJS can't get new html (query from MySQL)
当我使用EJS时,我在NodeJS中遇到了问题。
我有2个html页面。 第一个html页面供用户(客户端)设置查询范围,当他们按下“提交”按钮时,NodeJS将执行SQL查询,并将查询响应给第二个html。
我的问题是:当我测试查询时,我可以在我的控制台中看到查询,但它只是停止...
这是我的NodeJS代码:
var express = require("express");
var app = express();
var ejs = require("ejs");
app.set('views','./views');
app.set('views engine','ejs');
app.get('/graph4', function (req, res, next) {
var sql = `select A.card_id, A.state_id state,A.city_id city,A.mail,DATE_FORMAT(A.first_active_month,'%M %Y') first_active_month,B.score loyalty from users A left outer join loyalty B on A.card_id = B.card_id where B.score between -10 and -9 limit 1`;
var rows = []
fetchData(sql , function (rows) {
var now = new Date();
var today = now.getFullYear() + "/" + (now.getMonth() + 1) + "/" + now.getDate();
console.log(rows)
res.render("graph4.ejs", {
"title": "TEST",
"today": today,
"rows": rows
})
console.log("ejs end");
});
});
这是我的EJS代码:
<div style="text-align: center">
<%- include("graph4.ejs",{"title": title , "today": today }) %>
</div>
<table class="table table-bordered table-striped table-hover table-heading table-datatable" id="ordersTable">
<thead><tr>
<th>ID</th>
<th>State</th>
<th>City</th>
<th>Email</th>
<th>Activate_Day</th>
<th>loyalty</th>
</tr>
</thead>
<tbody>
<% rows.forEach(function(row) {%>
<tr>
<td><%= row.card_id %></td>
<td><%= row.state %></td>
<td><%= row.city %></td>
<td><%= row.mail %></td>
<td><%= row.first_active_month %></td>
<td><%= row.loyalty %></td>
</tr>
<%});%>
</tbody>
</table>
当我运行app.js
,我遇到了很多这样的错误: 在这里输入图像描述
我的第二个html(EJS)变成了这样(我刚看到同样的错误重复并重复): 在这里输入图像描述
因为您使用的名称(变量)没有描述文件的内容,所以您犯了一个错误并附加了同一个文件。
你看到了吗?
res.render("graph4.ejs",
<%- include("graph4.ejs",
您尝试渲染graph4.ejs
,其中包括graph4.ejs
,其中包括graph4.ejs
,其中包括graph4.ejs
,其中包含graph4.ejs
...直到包含/内存限制结束。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.