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' –