selectタグの下で選択されたオプションの値を取得しようとしています。下は私のejsファイルのスニペットで、node.js Expressフレームワークサーバー側の言語として。以下は食品のオプションです。オプションが選択されるとすぐに、データベースから価格でテキストフィールドを取得する必要があります。選択した食品の価格を表示するには、まず選択した商品の価格が必要です。これは私が立ち往生している部分です。私はアイテムを選択するとすぐに同じようにイベントをトリガする方法を知らない。誰か助けてくれますか?前もって感謝します。 この私が午前のHTMLファイルされる: - :node.jsを使用してselectタグの選択されたオプションの値にアクセスします。
const mysql = require('mysql'),
express = require('express'),
path = require('path'),
parser = require('body-parser'),
router = express.Router();
var conn = mysql.createConnection({
host: "localhost",
user: "root",
password: "0440",
database: "kfc"
})
conn.connect(function(err){
if(err) throw err;
console.log("Database connected")
})
app = express();
app.use(parser());
app.use(express.static(path.join(__dirname, 'public')));
app.get('/login', function(req, res){
res.sendFile(__dirname + '/public/login.html');
})
app.get('/dashboard', function(req, res){
res.render('pages/dashboard.ejs')
})
app.post('/dashboard', function(req, res){
conn.query("select id from login where id = ? and pwd = ?", [req.body.login, req.body.pwd], function(err, result, fields){
console.log(result);
if(err) throw err;
if(result.length > 0){
res.redirect('/dashboard');
console.log("Credentials verified")
}else{
console.log("Credentials incorrect");
res.redirect('/')
}
})
})
app.post('/bill', function (req, res) {
console.log("Hello"); //statement not getting executed
//HERE I AM TRYING TO CATCH THE VALUE OF THE SELECTED OPTION AND PASS IT INTO A QUERY
});
app.listen(8080);
多くのコンテキストがありません。 node.jsはサーバー上にあり、選択ボックスはブラウザーにあります。あなたのサーバーは、ブラウザで誰かが選択したことをどのように知っていますか?それは、Fredが日本の家にいるアラスカとウィルマの家にいるとき、フレッドがテーブルに置かれた飼育されたウィルマを食べることができない理由を尋ねるようなものです。さて、それはまったくそうではありませんが、それは私が思い付くことができる最も愚かな類推です。 –