我有这样的POST请求:
var urlencodedParser = bodyParser.urlencoded({ extended: false });
app.post('/readings', urlencodedParser,function(req, res){
console.log(req.body);
var Sensor = req.body;
res.render('readingsChart');
});
我想在app.post()之外使用“传感器”,在另一个GET请求中,例如:
var queryString = 'SELECT Time, Reading FROM myTable WHERE Sensor = '+Sensor;
app.get('/getSQL', function(req, res) {
connection.query(queryString, function(error, rows, fields) {
if(error){console.log(error);}
else{console.log('Connected');}
// My Code
});
});
我一直有这个错误:
var queryString = 'SELECT Time, Reading FROM '+table+' WHERE Sensor = '+Sensor;
^
ReferenceError: Sensor is not defined
先谢谢。