【发布时间】:2018-03-01 08:57:49
【问题描述】:
我想用 node js、mysql 和 express 创建一个日历。 这是我的 Calendar.js 代码:
$(document).ready(function() {
$('#calendar').fullCalendar({
theme: true,
eventLimit: true,
eventSources: [source]
});
});
我在文件 bdCalendar.js 中有 bd mysql“事件”表和数据。我不明白如何使用节点 js 将数据从表传输到数组源?
bdCalendar.js:
const mysql = require('mysql');
var bdCalendar = mysql.createConnection({
host: 'localhost',
user: 'admin',
password: 'admin',
database: 'event_calendar'
});
bdCalendar.connect((err) => {
if (err) throw err;
console.log('Connected');
});
bdCalendar.query("SELECT * FROM event", function(err, rows) {
if (err) {
throw err;
} else {
console.log(rows)
}
}
});
module.exports = bdCalendar;
我会很高兴有你的帮助!!!
【问题讨论】:
-
您的代码中的
[source]是什么?source是指向 nodeJS 服务器上的 URL 端点的变量吗? fullCalendar 只是使用它通过 ajax 向端点发出 HTTP 请求(传递您的服务器应该用来过滤返回事件列表的开始和结束日期),并且它期望以 fullCalendar 中描述的 JSON 格式返回响应文档。就像任何其他 ajax 请求一样,真的。您是否在节点中创建了端点?如果您不知道怎么做,请学习 nodeJS 教程。
标签: jquery mysql node.js express fullcalendar