【问题标题】:Get data from MariaDB with nodejs and send them to an html page (Express JS)使用 nodejs 从 MariaDB 获取数据并将它们发送到 html 页面(Express JS)
【发布时间】:2019-12-31 23:55:17
【问题描述】:

我需要从本地 Maria 数据库中获取一些数据,并将它们发送到 HTML 表中,以构建包含一些活动的日历。 我正在使用 Express JS 将用户重定向到特定的 HTML 页面。

这是我的文件结构:

NODE
|
|- app.js

PUBLIC
|
|- RESOURCES
   |
   |- PROPS
   |  |
   |  |- CSS
   |     |
   |     |- index.css
   |- SCRIPTS
      |
      |- index.js

index.html
foo.html

这是 app.js 的示例:

const express = require("express")
const app = express();
const path = require("path");

app.use(express.static("../public"));

app.get("/", function(req, res) {
  res.sendFile(path.join(__dirname + "/../index.html"));
});

app.listen(5000, () => {
  console.log("App listening on port 5000!");
});

我只需要在加载特定 HTML 文件时访问 MariaDB,例如 /about, 获取一些数据,并将它们发送到 JS 函数以编辑此表。

【问题讨论】:

  • 你有没有尝试过?你到底卡在哪里了?
  • 我真的不知道如何开始..

标签: javascript mysql node.js express mariadb


【解决方案1】:

您需要使用模板引擎来使用数据呈现视图。否则,您可以创建一个使用 mariadb 数据响应并使用 Javascript 发送请求的 api 端点。

【讨论】:

    猜你喜欢
    • 2017-12-15
    • 2021-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多