0
我得到一个HTML错误,试图通过建立一个连接呈现一个SQL数据库到索引页面。表名是员工,在终端上运行应用程序时没有错误,但在html链接上有错误页面。Nodejs连接到HTML
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/', function(req, res, next) {
GetData(function (recordSet) {
res.render('index', {product: recordSet})
console.log(recordSet);
});
});
function GetData(callBack){
var sql = require('mssql');
var Config = {
user: 'Gurpanth\\Gurpanth',
password: '',
database:'NodeJSDb',
server:'GURPANTH'
};
var conn = new sql.ConnectionPool(Config,function (err) {
//If any error
var request = new sql.Request(conn);
request.query('Select * from products', function(err, recordSet){
callBack(recordSet);
});
});
}
module.exports = router;
INDEX.EJS
<!DOCTYPE html>
<html>
<head>
<link rel='stylesheet' href='/stylesheets/style.css' />
</head>
<body>
<table>
<tbody>
<td><%=productName%></td>
</tbody>
</table>
</body>
</html>
html链接上的错误是什么? – turmuka
C:\ Users \ Gurpanth \ WebstormProjects \ Database \ views \ index.ejs:10 8 |
9 | >> 10 |<%= product.productName%> 11 | 12 | 13 |无法读取未定义的属性'productName' –