我創建了一個下拉選單,通過 axios post 將資料傳遞給 NodeJS 我可以在 nodejs Post 的控制臺日志中看到,但不能使用 post 函式之外的值
我想使用該值來查詢資料庫
我的 nodejs 代碼:
app.post('/getmodel', (req, res) => {
var model = req.body.model;
console.log(model);
//It shows model value here but can't able to use outside
});
app.get('/model', (req,res)=>{
let model = req.body.model;
let sql ="select * from new_schema.model_list,new_schema.images where model_name= " mysql.escape(model)
db.query(sql,model, (err,results) =>{
if(err){
throw err
}
console.log(results)
res.send(results);
})
})
我的反應代碼作業正常,因為我可以在下面的 nodejs 控制臺中看到選定的值

這些是從我的 nodejs 控制臺中顯示的下拉串列中選擇的值。但不能通過 req.body 使用它,請幫助我
uj5u.com熱心網友回復:
你可以這樣試試
app.post('/getmodel', (req, res) => {
var model = req.body.model;
console.log(model);
//It shows model value here and you can able to use in the query
let sql = "select * from new_schema.model_list,new_schema.images where model_name= " mysql.escape(model)
db.query(sql, model, (err, results) => {
if (err) {
throw err
}
console.log(results)
res.send(results);
})
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/334336.html
