我在Express中获取URL参数时遇到问题。 在客户端(角),我定义状态(ui.router),并用新的状态发送URL(ID):如何在Express中获取URL参数?
.state('home.detail', {
url: '/:id',
templateUrl: 'views/detail.html',
controller: 'DetailController'
});
在后端,我试图让这个URL(ID)
app.get('/api/:id', function(req,res){
var id = req.query.id;
console.log(id);
var queryString = "SELECT * FROM `table` WHERE table.ID=id";
//add to a callback
connection.query(queryString, function (error, results) {
if(error) {
throw error;
}
else {
// send JSON object to the client
res.end(JSON.stringify(results));
//console.log(res);
}
});
});
但我得到了undefined
id(console.log(id))的值。 我做错了什么?
请让我知道,如果我的回答你解决问题了:) – IggY